Documentation
¶
Overview ¶
Package dispatch implements the task dispatcher: an in-memory active-queue scheduler (min-heap + token buckets), budgeted claims against the store, HTTP delivery workers, the lease sweeper, and retention cleanup.
Correctness never depends on this process being the only dispatcher — every completion is fenced by the task's lease token. Leadership (when a LeaderElector is configured) is purely an optimization to avoid duplicate claim scans.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Backoff ¶
func Backoff(rc store.RetryConfig, attempts int) time.Duration
Backoff returns the delay before the next attempt, given that `attempts` attempts have completed. GCP Cloud Tasks semantics: the interval starts at MinBackoff, doubles MaxDoublings times, then grows linearly by 2^MaxDoublings × MinBackoff per retry, capped at MaxBackoff.
Example (GCP docs): min=10s max=300s doublings=3 → 10, 20, 40, 80, 160, 240, 300, 300, …
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
func (*Dispatcher) Role ¶
func (d *Dispatcher) Role() string
func (*Dispatcher) Start ¶
func (d *Dispatcher) Start(ctx context.Context)
func (*Dispatcher) Stop ¶
func (d *Dispatcher) Stop()
Stop resigns leadership, drains in-flight dispatches (up to DrainTimeout), and blocks until the loop exits.
type LeaderElector ¶
type LeaderElector interface {
// Acquire blocks until leadership is held or ctx ends. The returned
// channel closes if leadership is later lost.
Acquire(ctx context.Context) (lost <-chan struct{}, err error)
// Release gives leadership up (e.g. on graceful shutdown).
Release()
}
LeaderElector serializes the dispatcher role across replicas (Postgres advisory lock in production).
type Options ¶
type Options struct {
GlobalConcurrency int
PerQueueClaimCap int
ReconcileInterval time.Duration
SweepInterval time.Duration
CleanupInterval time.Duration
LeaseGrace time.Duration
DrainTimeout time.Duration
RetentionSucceeded time.Duration
RetentionFailed time.Duration
DedupWindow time.Duration
Clock clockwork.Clock // nil = real clock
HTTPClient *http.Client // nil = tuned default
Leader LeaderElector // nil = always leader (single node)
}