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. When the worker is about to dead-letter a job (terminal failure after MaxAttempts), it calls OnDeadLetter FIRST so the handler can drive its backing domain entity (agent session / recon run) to a terminal state. Without it, a reconciler that keys on the ENTITY's status – not the job's – re-enqueues the stranded entity forever (the dead-letter → re-drive livelock), and the job/entity states permanently disagree. Best-effort: an OnDeadLetter error is logged, never blocking the dead-letter itself. cause is the last handler error that exhausted the retries.
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.