
tickrunner
Index
- Constants
- func ComponentLogger(slug string) *slog.Logger
- func HandlePassResult(ctx context.Context, log *slog.Logger, manager QuotaMetricsRefresher, count int, err error, countKey string) error
- type AdvisoryLocker
- type Config
- type QuotaMetricsRefresher
- type Service
Constants
MsgPassFailed / MsgPassCompleted / MsgQuotaMetricsRefreshFailed are the canonical terminal-event log messages shared by the periodic “pass” workers (rebalance, replication, over-replication). Held as constants so the three nearly-identical work closures cannot drift.
func ComponentLogger
ComponentLogger returns the canonical scoped logger every Service uses, derived from the snake_case slug so the component attr is the single source of truth for log filtering. Callers typically pass the same slug as Service.Name.
func HandlePassResult
HandlePassResult is the shared post-call handling for the three nearly-identical “pass” workers (rebalance, over-replication, replication). Each one returns (count, err) from a worker call and then either: surfaces non-DB errors as tick failures (so health reporting sees them), or - when work was done - logs a completion message with a work-specific count key and refreshes quota metrics so the dashboard reflects the move. Centralised so the three closures cannot drift, and so coverage of the error and count>0 branches lands in one place.
type AdvisoryLocker
AdvisoryLocker is the consumer-defined slice of the metadata store a Service needs: one TryAdvisoryLock call per tick. The concrete metadata store satisfies this implicitly.
type Config
Config bundles the inputs needed to construct a Service. Held as a struct so callers can pin a few fields and leave the rest at their zero values rather than threading a long argument list. ShouldRun, Startup, and OnError are optional; Work and Name are required.
type QuotaMetricsRefresher
QuotaMetricsRefresher is the single-method subset of *proxy.BackendManager that HandlePassResult calls to push fresh quota gauges after a successful worker pass. Lives here so the worker packages can take it as a typed dep without importing DI.
type Service
Service runs a function on a fixed interval under an advisory lock. Handles audit context creation, lock acquisition, skip/error logging, and context cancellation. The component identity lives on the scoped logger (component attr) rather than in message text, so logs from every service share the same shape and operators filter by attribute.
Per-service health state (lastSuccess, lastFailure, lastError, consecutiveFailures) is recorded after each tick so operators can query worker liveness through the admin endpoint and alert on staleness through Prometheus.
func New
New constructs a Service from cfg. Required fields (Locker, Interval, LockID, Name, Log, Work) must be non-nil/positive; the constructor trusts the caller to supply them.
func (*Service) Health
Health implements lifecycle.HealthReporter. Returns a snapshot of the service’s last tick outcomes plus its registered name so the admin endpoint can render a per-service status table.
func (*Service) Interval
Interval returns the configured tick period. Exposed so DI invariant tests can pin “no interval is zero or pathologically large.”
func (*Service) LockID
LockID returns the advisory-lock identifier this service holds per tick. Exposed so DI invariant tests can pin “no two services share a lock ID.”
func (*Service) Name
Name returns the snake_case component slug the service was constructed with. Exposed for tests that validate cross-service invariants (unique lock IDs, sane intervals) and for any future admin tooling that wants per-service identification.
func (*Service) Run
Run implements lifecycle.Runner with a jittered first tick to prevent thundering herd on the advisory lock at startup.
func (*Service) Tick
Tick drives a single iteration of the work function under the same lock + audit + health-recording path Run uses. Exposed for tests that want to verify per-tick behaviour without spinning the full ticker loop, and for any future admin endpoint that wants to force a tick.
Generated by gomarkdoc