Documentation
¶
Overview ¶
Package scheduler provides a small retry-aware job runner that can be embedded in services needing persisted scheduling semantics.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttemptUpdate ¶
type AttemptUpdate struct {
Status string
ProviderMessageID string
RetryCount int
LastAttemptedAt time.Time
}
AttemptUpdate describes the mutation that must be persisted after a dispatch attempt.
type ClaimingRepository ¶ added in v0.2.1
type ClaimingRepository interface {
ClaimJobForAttempt(ctx context.Context, job Job, attemptedAt time.Time) (bool, error)
}
ClaimingRepository optionally provides an ownership claim gate before dispatch.
type Config ¶
type Config struct {
Repository Repository
Dispatcher Dispatcher
Logger *slog.Logger
Interval time.Duration
MaxRetries int
SuccessStatus string
FailureStatus string
Clock Clock
}
Config contains all inputs required to construct a Worker.
type DispatchResult ¶
DispatchResult carries dispatcher-supplied metadata, including status overrides and provider IDs.
type Dispatcher ¶
type Dispatcher interface {
Attempt(ctx context.Context, job Job) (DispatchResult, error)
}
Dispatcher performs the effectful work for a job (sending an email, firing an SMS, etc.).
type Job ¶
type Job struct {
ID string
ScheduledFor *time.Time
RetryCount int
LastAttemptedAt time.Time
Payload any
}
Job represents a scheduled unit of work alongside metadata the scheduler needs for backoff decisions.
type Repository ¶
type Repository interface {
PendingJobs(ctx context.Context, maxRetries int, now time.Time) ([]Job, error)
ApplyAttemptResult(ctx context.Context, job Job, update AttemptUpdate) error
}
Repository exposes persistence hooks for fetching pending jobs and recording attempt results.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker orchestrates scheduled retries with exponential backoff and contextual logging.