Documentation
¶
Overview ¶
Package worker is the durable-queue claim-loop: it pulls jobs from a ports.JobQueue, dispatches each to a Handler registered by Kind, heartbeats long runs so their lease does not expire mid-flight, and Completes or Fails (with backoff) the job. It is the process body of synapse-worker, and reusable in-process. It owns no business logic – the handlers (recon/SCA) carry the same gate/audit/ evidence invariants as the synchronous path.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Visibility time.Duration // lease per claim
Poll time.Duration // idle sleep when the queue is empty
Heartbeat time.Duration // lease-extension interval for an in-flight job
Backoff time.Duration // base requeue delay on failure
MaxAttempts int // give up (dead-letter) after this many deliveries
}
Config tunes the loop; zero values fall back to sane defaults.
type DeadLetterer ¶
type DeadLetterer interface {
OnDeadLetter(ctx context.Context, job ports.QueuedJob, cause error) error
}
DeadLetterer is an optional capability a Handler may implement after the fenced queue transition has successfully dead-lettered a terminally failed job. Running it after the fence check prevents a stale worker from finalizing entity state owned by a newer claim. Best-effort: an OnDeadLetter error is logged after the authoritative queue transition.
type Enqueuer ¶
type Enqueuer interface {
Enqueue(ctx context.Context, kind string, payload []byte) (string, error)
}
Enqueuer is the write side a use case uses to defer work to the worker. It is the subset of ports.JobQueue producers need.
type Handler ¶
Handler processes one claimed job. A nil error means success (the job is Completed); any error requeues the job with backoff until MaxAttempts is reached. Handlers must be IDEMPOTENT: at-least-once delivery means a job can run more than once (e.g. after a crash mid-run), and recon hits real hosts.
type HandlerFunc ¶
HandlerFunc adapts a function to Handler.
type RetryDirective ¶ added in v0.2.0
RetryDirective lets a handler classify a transport failure without changing retry behavior for existing job kinds. Terminal failures dead-letter now; RetryAfter schedules the durable queue without sleeping a worker goroutine.