Documentation
¶
Index ¶
- Constants
- Variables
- func CancelJob(ctx context.Context, q any, jobID string) error
- func ClearQueue(ctx context.Context, q any, queueName string) error
- func DeleteJob(ctx context.Context, q any, queueName, jobID string) error
- func DriverUniqueKey(job Job, queueName string) string
- func IsPermanent(err error) bool
- func Pause(ctx context.Context, q any, queueName string) error
- func Permanent(err error) error
- func PhysicalQueueName(defaultQueue string, queueName string) string
- func PhysicalQueueWeights(defaultQueue string, weights map[string]int) map[string]int
- func Ready(ctx context.Context, q any) error
- func ResolveObservedJobType(rawType string, payload []byte) string
- func Resume(ctx context.Context, q any, queueName string) error
- func RetryJob(ctx context.Context, q any, queueName, jobID string) error
- func SafeObserve(ctx context.Context, observer Observer, event Event)
- func SupportsNativeStats(q any) bool
- func SupportsPause(q any) bool
- func SupportsQueueAdmin(q any) bool
- func ValidateDriverJob(job Job) error
- type BatchBuilder
- type BatchJob
- type BatchJobOutcome
- type BatchRecord
- type BatchState
- type ChainBuilder
- type ChainNode
- type ChainRecord
- type ChainState
- type ChannelObserver
- type Config
- type Continuation
- type ContinuationBuilder
- func (b *ContinuationBuilder) Dispatch(ctx context.Context) (string, error)
- func (b *ContinuationBuilder) OnCompletion(job Job) *ContinuationBuilder
- func (b *ContinuationBuilder) OnFailure(job Job) *ContinuationBuilder
- func (b *ContinuationBuilder) OnProgress(job Job) *ContinuationBuilder
- func (b *ContinuationBuilder) OnSuccess(job Job) *ContinuationBuilder
- type ContinuationDefinition
- type ContinuationOutcome
- type ContinuationRecord
- type ContinuationSummary
- type DatabaseConfig
- type DispatchRecord
- type DispatchResult
- type Driver
- type DriverJobMetadata
- type DriverJobOptions
- type Event
- type EventKind
- type EventLayer
- type FailOnError
- type FakeQueue
- func (f *FakeQueue) AssertBatchCount(t testing.TB, expected int)
- func (f *FakeQueue) AssertBatched(t testing.TB, predicate func(BatchRecord) bool)
- func (f *FakeQueue) AssertChained(t testing.TB, expected []string)
- func (f *FakeQueue) AssertCount(t testing.TB, expected int)
- func (f *FakeQueue) AssertDispatched(t testing.TB, jobType string)
- func (f *FakeQueue) AssertDispatchedOn(t testing.TB, queueName, jobType string)
- func (f *FakeQueue) AssertDispatchedTimes(t testing.TB, jobType string, expected int)
- func (f *FakeQueue) AssertNotDispatched(t testing.TB, jobType string)
- func (f *FakeQueue) AssertNothingBatched(t testing.TB)
- func (f *FakeQueue) AssertNothingDispatched(t testing.TB)
- func (f *FakeQueue) Batch(jobs ...Job) BatchBuilder
- func (f *FakeQueue) BatchRecords() []BatchRecord
- func (f *FakeQueue) BusDispatch(ctx context.Context, jobType string, payload []byte, ...) error
- func (f *FakeQueue) BusDispatchDirect(ctx context.Context, jobType string, payload []byte, ...) error
- func (f *FakeQueue) BusRegister(string, busruntime.Handler)
- func (f *FakeQueue) Chain(jobs ...Job) ChainBuilder
- func (f *FakeQueue) ChainRecords() []ChainRecord
- func (f *FakeQueue) ContinuationRecords() []ContinuationRecord
- func (f *FakeQueue) Dispatch(job any) error
- func (f *FakeQueue) Driver() Driver
- func (f *FakeQueue) FindBatch(ctx context.Context, batchID string) (BatchState, error)
- func (f *FakeQueue) FindChain(ctx context.Context, chainID string) (ChainState, error)
- func (f *FakeQueue) FindContinuations(ctx context.Context, id string) ([]ContinuationOutcome, error)
- func (f *FakeQueue) Prune(ctx context.Context, before time.Time) error
- func (f *FakeQueue) Ready(ctx context.Context) error
- func (f *FakeQueue) Records() []DispatchRecord
- func (f *FakeQueue) Register(string, Handler)
- func (f *FakeQueue) Reset()
- func (f *FakeQueue) Shutdown(context.Context) error
- func (f *FakeQueue) StartWorkers(context.Context) error
- func (f *FakeQueue) WithContext(ctx context.Context) queueRuntime
- func (f *FakeQueue) Workers(int) queueRuntime
- type Handler
- type Job
- func (t Job) Backoff(backoff time.Duration) Job
- func (t Job) Bind(dst any) error
- func (t Job) Delay(delay time.Duration) Job
- func (t Job) OnQueue(name string) Job
- func (t Job) Payload(payload any) Job
- func (t Job) PayloadAs[T any]() (T, error)
- func (t Job) PayloadBytes() []byte
- func (t Job) PayloadJSON(v any) Job
- func (t Job) Retry(maxRetry int) Job
- func (t Job) Timeout(timeout time.Duration) Job
- func (t Job) UniqueFor(ttl time.Duration) Job
- type JobSnapshot
- type JobState
- type ListJobsOptions
- type ListJobsResult
- type Lock
- type Locker
- type Logger
- type Message
- type Middleware
- type MiddlewareFunc
- type Next
- type NoopLogger
- type ObservedJobMetadata
- type Observer
- type ObserverFunc
- type Option
- func WithClock(clock func() time.Time) Option
- func WithHandlerContextDecorator(fn func(context.Context) context.Context) Option
- func WithLegacyDirectEnvelope() Option
- func WithMiddleware(middlewares ...Middleware) Option
- func WithObserver(observer Observer) Option
- func WithResourceID(id string) Option
- func WithStore(store WorkflowStore) Option
- func WithWorkers(count int) Option
- type Queue
- func (r *Queue) Batch(jobs ...Job) BatchBuilder
- func (r *Queue) CancelJob(ctx context.Context, jobID string) error
- func (r *Queue) Chain(jobs ...Job) ChainBuilder
- func (r *Queue) ClearQueue(ctx context.Context, queueName string) error
- func (r *Queue) DeleteJob(ctx context.Context, queueName, jobID string) error
- func (r *Queue) Dispatch(job Job) (DispatchResult, error)
- func (r *Queue) Driver() Driver
- func (r *Queue) FindBatch(ctx context.Context, batchID string) (BatchState, error)
- func (r *Queue) FindChain(ctx context.Context, chainID string) (ChainState, error)
- func (r *Queue) FindContinuations(ctx context.Context, id string) ([]ContinuationOutcome, error)
- func (r *Queue) History(ctx context.Context, queueName string, window QueueHistoryWindow) ([]QueueHistoryPoint, error)
- func (r *Queue) ListJobs(ctx context.Context, opts ListJobsOptions) (ListJobsResult, error)
- func (r *Queue) Pause(ctx context.Context, queueName string) error
- func (r *Queue) Prune(ctx context.Context, before time.Time) error
- func (r *Queue) Ready(ctx context.Context) error
- func (r *Queue) Register(jobType string, handler func(context.Context, Message) error)
- func (r *Queue) Resume(ctx context.Context, queueName string) error
- func (r *Queue) RetryJob(ctx context.Context, queueName, jobID string) error
- func (r *Queue) Run(ctx context.Context) error
- func (r *Queue) Shutdown(ctx context.Context) error
- func (r *Queue) StartWorkers(ctx context.Context) error
- func (r *Queue) Stats(ctx context.Context) (StatsSnapshot, error)
- func (r *Queue) WithContext(ctx context.Context) *Queue
- func (r *Queue) WithWorkers(count int) *Queue
- type QueueAdmin
- type QueueController
- type QueueCounters
- type QueueHistoryPoint
- func QueueHistory(ctx context.Context, q any, queueName string, window QueueHistoryWindow) ([]QueueHistoryPoint, error)
- func SinglePointHistory(snapshot StatsSnapshot, queueName string) []QueueHistoryPoint
- func TimelineHistoryFromSnapshot(snapshot StatsSnapshot, queueName string, window QueueHistoryWindow) []QueueHistoryPoint
- type QueueHistoryProvider
- type QueueHistoryWindow
- type QueueThroughput
- type RateLimit
- type RateLimiter
- type RetryPolicy
- type SQLStoreConfig
- type SkipWhen
- type StatsCollector
- type StatsProvider
- type StatsSnapshot
- func (s StatsSnapshot) Active(name string) int64
- func (s StatsSnapshot) Archived(name string) int64
- func (s StatsSnapshot) Failed(name string) int64
- func (s StatsSnapshot) Paused(name string) int64
- func (s StatsSnapshot) Pending(name string) int64
- func (s StatsSnapshot) Processed(name string) int64
- func (s StatsSnapshot) Queue(name string) (QueueCounters, bool)
- func (s StatsSnapshot) Queues() []string
- func (s StatsSnapshot) RetryCount(name string) int64
- func (s StatsSnapshot) Scheduled(name string) int64
- func (s StatsSnapshot) Throughput(name string) (QueueThroughput, bool)
- type StoredJob
- type StoredJobOptions
- type ThroughputWindow
- type WithoutOverlapping
- type WorkerpoolConfig
- type WorkflowOutcomeStore
- type WorkflowStore
Constants ¶
const DriverJobMetadataVersion = busruntime.DeliveryMetadataVersion
DriverJobMetadataVersion identifies the direct-delivery metadata understood by this version of the driver integration contract. @group Driver Integration
Variables ¶
var ( // ErrSkipped identifies a job intentionally suppressed by middleware. ErrSkipped = errors.New("bus job skipped by middleware") // ErrRateLimited identifies a job rejected by its configured rate limiter. ErrRateLimited = errors.New("bus job rate limited") // ErrOverlapping identifies a job rejected because its execution key is already locked. ErrOverlapping = errors.New("bus job overlap prevented") )
var ErrBackoffUnsupported = errors.New("backoff option is not supported by this driver")
ErrBackoffUnsupported indicates requested backoff is unsupported by a driver.
var ErrDuplicate = errors.New("duplicate job")
ErrDuplicate indicates a duplicate unique job enqueue.
var ErrPauseUnsupported = errors.New("pause/resume is not supported by this driver")
ErrPauseUnsupported indicates queue pause/resume is unsupported by a driver.
var ErrQueueAdminUnsupported = errors.New("queue admin is not supported by this driver")
ErrQueueAdminUnsupported indicates queue admin operations are unsupported by a driver. @group Admin
var ErrQueuePaused = errors.New("queue is paused")
ErrQueuePaused indicates enqueue was rejected because queue is paused.
var ErrQueuerShuttingDown = errors.New("queue is shutting down")
ErrQueuerShuttingDown indicates enqueue was rejected during shutdown.
var ErrWorkerpoolQueueNotInitialized = errors.New("workerpool queue not initialized")
ErrWorkerpoolQueueNotInitialized indicates workerpool queue is unavailable.
var ErrWorkflowNotFound = workflow.ErrNotFound
ErrWorkflowNotFound indicates a workflow state record is not present. @group Queue
var ErrWorkflowUnsupported = errors.New("portable workflows are unsupported")
ErrWorkflowUnsupported indicates that the selected driver cannot perform a portable workflow operation. @group Queue
Functions ¶
func CancelJob ¶
CancelJob cancels a job when supported. @group Admin
Example: cancel a job via helper
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
err = queue.CancelJob(context.Background(), q, "job-id")
_ = err
func ClearQueue ¶
ClearQueue clears queue jobs when supported. @group Admin
Example: clear queue via helper
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
err = queue.ClearQueue(context.Background(), q, "default")
_ = err
func DeleteJob ¶
DeleteJob deletes a job when supported. @group Admin
Example: delete a job via helper
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
err = queue.DeleteJob(context.Background(), q, "default", "job-id")
_ = err
func DriverUniqueKey ¶ added in v0.3.0
DriverUniqueKey returns a versioned queue-scoped identity for driver deduplication. Correlation IDs and delivery policy are excluded when a workflow envelope carries a logical job. @group Driver Integration
func IsPermanent ¶ added in v0.3.0
IsPermanent reports whether an error requests terminal application settlement. @group Queue
func Pause ¶
Pause pauses queue consumption for drivers that support it. @group Observability
Example: pause queue
q, _ := queue.NewSync()
_ = queue.Pause(context.Background(), q, "default")
snapshot, _ := queue.Snapshot(context.Background(), q, nil)
fmt.Println(snapshot.Paused("default"))
// Output: 1
func Permanent ¶ added in v0.3.0
Permanent marks an error as terminal so workers do not spend the remaining application retry budget on it. @group Queue
func PhysicalQueueName ¶ added in v0.1.17
PhysicalQueueName maps a logical queue name into the physical name used by the backing queue driver.
func PhysicalQueueWeights ¶ added in v0.1.17
PhysicalQueueWeights maps logical weighted queue names into their physical backend names.
func Ready ¶
Ready validates backend readiness for the provided queue runtime. @group Observability
Example: ready via package helper
q, _ := queue.NewSync() fmt.Println(queue.Ready(context.Background(), q) == nil) // true
func ResolveObservedJobType ¶ added in v0.1.8
ResolveObservedJobType returns the effective application job type that should be emitted to observers. External workers may process private workflow delivery envelopes (for example, "bus:job") whose payload embeds the real application job type. When possible, this helper unwraps that payload so dashboards and metrics reflect the user-facing job type instead of the transport wrapper.
func Resume ¶
Resume resumes queue consumption for drivers that support it. @group Observability
Example: resume queue
q, _ := queue.NewSync()
_ = queue.Pause(context.Background(), q, "default")
_ = queue.Resume(context.Background(), q, "default")
snapshot, _ := queue.Snapshot(context.Background(), q, nil)
fmt.Println(snapshot.Paused("default"))
// Output: 0
func RetryJob ¶
RetryJob retries (runs now) a job when supported. @group Admin
Example: retry a job via helper
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
err = queue.RetryJob(context.Background(), q, "default", "job-id")
_ = err
func SafeObserve ¶
SafeObserve delivers an event to an observer and recovers observer panics.
This is an advanced helper intended for driver-module implementations. @group Observability
func SupportsNativeStats ¶
SupportsNativeStats reports whether a queue runtime exposes native stats snapshots. @group Observability
Example: check native stats support
q, _ := queue.NewSync() fmt.Println(queue.SupportsNativeStats(q)) // Output: true
func SupportsPause ¶
SupportsPause reports whether a queue runtime supports Pause/Resume. @group Observability
Example: check pause support
q, _ := queue.NewSync() fmt.Println(queue.SupportsPause(q)) // Output: true
func SupportsQueueAdmin ¶
SupportsQueueAdmin reports whether queue admin operations are available. @group Admin
Example: detect admin support
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
fmt.Println(queue.SupportsQueueAdmin(q))
// Output: true
func ValidateDriverJob ¶
ValidateDriverJob validates a job value for backend dispatch.
This is an advanced helper intended for driver-module implementations. @group Driver Integration
Types ¶
type BatchBuilder ¶
type BatchBuilder interface {
// Name assigns an application-facing label to the batch.
Name(name string) BatchBuilder
// OnQueue applies a default queue to batch jobs without an explicit target.
OnQueue(queue string) BatchBuilder
// AllowFailures keeps remaining members active after a terminal member failure.
AllowFailures() BatchBuilder
// Progress registers the explicitly ephemeral batch progress callback.
Progress(fn func(ctx context.Context, st BatchState) error) BatchBuilder
// Then registers the explicitly ephemeral batch success callback.
Then(fn func(ctx context.Context, st BatchState) error) BatchBuilder
// Catch registers the explicitly ephemeral batch failure callback.
Catch(fn func(ctx context.Context, st BatchState, err error) error) BatchBuilder
// Finally registers the explicitly ephemeral batch terminal callback.
Finally(fn func(ctx context.Context, st BatchState) error) BatchBuilder
// Dispatch persists and starts the batch workflow.
Dispatch(ctx context.Context) (string, error)
}
BatchBuilder is the high-level batch workflow builder. @group Queue
type BatchJobOutcome ¶ added in v0.3.0
type BatchJobOutcome string
BatchJobOutcome identifies the durable result that first settled one batch member. @group Queue
const ( // BatchJobSucceeded records successful member settlement. // @group Queue BatchJobSucceeded BatchJobOutcome = "succeeded" // BatchJobFailed records failed member settlement. // @group Queue BatchJobFailed BatchJobOutcome = "failed" )
type BatchRecord ¶ added in v0.3.0
type BatchRecord struct {
BatchID string
DispatchID string
Name string
Queue string
AllowFailed bool
Jobs []BatchJob
CreatedAt time.Time
}
BatchRecord is the persisted representation used to create a batch workflow. @group Queue
type BatchState ¶
type BatchState struct {
BatchID string
DispatchID string
Name string
Queue string
AllowFailed bool
Total int
Pending int
Processed int
Failed int
Cancelled bool
Completed bool
CreatedAt time.Time
UpdatedAt time.Time
}
BatchState is the persisted aggregate execution view of a batch workflow. @group Queue
type ChainBuilder ¶
type ChainBuilder interface {
// OnQueue applies a default queue to chain jobs without an explicit target.
OnQueue(queue string) ChainBuilder
// Catch registers the explicitly ephemeral chain failure callback.
Catch(fn func(ctx context.Context, st ChainState, err error) error) ChainBuilder
// Finally registers the explicitly ephemeral chain terminal callback.
Finally(fn func(ctx context.Context, st ChainState) error) ChainBuilder
// Dispatch persists and starts the chain workflow.
Dispatch(ctx context.Context) (string, error)
}
ChainBuilder is the high-level chain workflow builder. @group Queue
type ChainRecord ¶ added in v0.3.0
type ChainRecord struct {
ChainID string
DispatchID string
Queue string
Nodes []ChainNode
CreatedAt time.Time
}
ChainRecord is the persisted representation used to create a chain workflow. @group Queue
type ChainState ¶
type ChainState struct {
ChainID string
DispatchID string
Queue string
Nodes []ChainNode
NextIndex int
Completed bool
Failed bool
Failure string
CreatedAt time.Time
UpdatedAt time.Time
}
ChainState is the persisted view of a chain workflow. @group Queue
type ChannelObserver ¶
ChannelObserver forwards events to a channel. @group Observability
func (ChannelObserver) Observe ¶
func (c ChannelObserver) Observe(_ context.Context, event Event)
Observe forwards an event to the configured channel. @group Observability
Example: channel observer
ch := make(chan queue.Event, 1)
observer := queue.ChannelObserver{Events: ch}
observer.Observe(context.Background(), queue.Event{Kind: queue.EventProcessStarted, Queue: "default"})
event := <-ch
_ = event
type Config ¶
Config configures queue creation for New (and advanced driver/runtime interop). @group Config
type Continuation ¶ added in v0.3.0
type Continuation = busruntime.Continuation
Continuation identifies a durable workflow hook invocation independently of its job payload.
type ContinuationBuilder ¶ added in v0.3.0
type ContinuationBuilder struct {
// contains filtered or unexported fields
}
ContinuationBuilder binds named durable hooks to a snapshot of a configured workflow. Configure the ChainBuilder or BatchBuilder before passing it to Continue.
func Continue ¶ added in v0.3.0
func Continue(builder any) *ContinuationBuilder
Continue snapshots a queue-owned chain or batch without changing existing builder interfaces. Unsupported custom builders and mixed closure callbacks fail when Dispatch is called. @group Workflows
Example: named durable completion
q, err := queue.NewSync(queue.WithResourceID("reports"))
if err != nil {
return
}
q.Register("reports:build", func(context.Context, queue.Message) error { return nil })
q.Register("reports:complete", func(_ context.Context, m queue.Message) error {
invocation, _ := m.Continuation()
_ = invocation.ID // Stable across retry, suitable for application idempotency.
return nil
})
if err := q.StartWorkers(context.Background()); err != nil {
return
}
defer q.Shutdown(context.Background())
id, err := queue.Continue(q.Chain(queue.NewJob("reports:build"))).
OnCompletion(queue.NewJob("reports:complete")).Dispatch(context.Background())
_ = id
_ = err
func (*ContinuationBuilder) Dispatch ¶ added in v0.3.0
func (b *ContinuationBuilder) Dispatch(ctx context.Context) (string, error)
Dispatch validates and accepts one immutable workflow with its durable hook definitions.
func (*ContinuationBuilder) OnCompletion ¶ added in v0.3.0
func (b *ContinuationBuilder) OnCompletion(job Job) *ContinuationBuilder
OnCompletion appends a named hook to the first aggregate terminal transition.
func (*ContinuationBuilder) OnFailure ¶ added in v0.3.0
func (b *ContinuationBuilder) OnFailure(job Job) *ContinuationBuilder
OnFailure appends a named hook to the first terminal business failure.
func (*ContinuationBuilder) OnProgress ¶ added in v0.3.0
func (b *ContinuationBuilder) OnProgress(job Job) *ContinuationBuilder
OnProgress appends a named hook for each first committed batch member outcome.
func (*ContinuationBuilder) OnSuccess ¶ added in v0.3.0
func (b *ContinuationBuilder) OnSuccess(job Job) *ContinuationBuilder
OnSuccess appends a named hook to the workflow's successful aggregate transition.
type ContinuationDefinition ¶ added in v0.3.0
ContinuationDefinition describes a named hook without representing a triggered invocation.
type ContinuationOutcome ¶ added in v0.3.0
type ContinuationOutcome = busruntime.ContinuationOutcome
ContinuationOutcome reports a triggered hook's durable scheduling and settlement.
type ContinuationRecord ¶ added in v0.3.0
type ContinuationRecord struct {
WorkflowID string
Definitions []ContinuationDefinition
}
ContinuationRecord contains the immutable hook catalog of an accepted fake workflow.
type ContinuationSummary ¶ added in v0.3.0
type ContinuationSummary = busruntime.ContinuationSummary
ContinuationSummary contains immutable safe trigger counters and member identity.
type DatabaseConfig ¶
type DatabaseConfig struct {
DB *sql.DB
DriverName string
DSN string
Workers int
PollInterval time.Duration
DefaultQueue string
AutoMigrate bool
DisableAutoMigrate bool
ProcessingRecoveryGrace time.Duration
ProcessingLeaseNoTimeout time.Duration
Observer Observer
Logger Logger
}
DatabaseConfig configures the SQL-backed database q. @group Config
type DispatchRecord ¶
DispatchRecord captures one dispatch observed by FakeQueue. @group Testing
type DispatchResult ¶
type DispatchResult struct {
DispatchID string
}
DispatchResult identifies an accepted logical dispatch. @group Queue
type Driver ¶
type Driver string
Driver identifies the queue backend. @group Driver
Example: driver values
fmt.Println(queue.DriverNull, queue.DriverSync, queue.DriverWorkerpool, queue.DriverDatabase, queue.DriverRedis, queue.DriverNATS, queue.DriverSQS, queue.DriverRabbitMQ)
const ( // DriverNull drops dispatched jobs and performs no execution. DriverNull Driver = "null" // DriverSync runs handlers inline in the caller goroutine. DriverSync Driver = "sync" // DriverWorkerpool runs handlers on an in-memory workerpool. DriverWorkerpool Driver = "workerpool" // DriverDatabase selects the SQL-backed queue backend. DriverDatabase Driver = "database" // DriverRedis selects the Redis (asynq) backend. DriverRedis Driver = "redis" // DriverNATS selects the NATS backend. DriverNATS Driver = "nats" // DriverSQS selects the AWS SQS backend. DriverSQS Driver = "sqs" // DriverTemporal selects the optional Temporal workflow backend. DriverTemporal Driver = "temporal" // DriverRabbitMQ selects the RabbitMQ backend. DriverRabbitMQ Driver = "rabbitmq" )
type DriverJobMetadata ¶ added in v0.3.0
type DriverJobMetadata = busruntime.DeliveryMetadata
DriverJobMetadata carries stable correlation separately from an application's job type and payload. Drivers persist this metadata alongside their native delivery representation so ordinary jobs do not require a workflow envelope.
This is an advanced type intended for optional driver integrations. @group Driver Integration
func DriverMetadata ¶ added in v0.3.0
func DriverMetadata(job Job) DriverJobMetadata
DriverMetadata returns supported direct-delivery correlation attached to job. Unknown metadata versions are intentionally hidden so older workers do not trust fields whose semantics they cannot validate.
This is an advanced helper intended for driver-module implementations. @group Driver Integration
type DriverJobOptions ¶
type DriverJobOptions struct {
QueueName string
Timeout *time.Duration
MaxRetry *int
Attempt int
Backoff *time.Duration
Delay time.Duration
UniqueTTL time.Duration
}
DriverJobOptions exposes parsed job enqueue metadata for driver-module implementations.
This is an advanced type intended for optional driver integrations. @group Driver Integration
func DriverOptions ¶
func DriverOptions(job Job) DriverJobOptions
DriverOptions returns parsed enqueue metadata for backend dispatch.
This is an advanced helper intended for driver-module implementations. @group Driver Integration
type Event ¶
type Event struct {
SchemaVersion int
EventID string
Layer EventLayer
Kind EventKind
Driver Driver
Queue string
JobType string
JobKey string
DispatchID string
JobID string
ChainID string
BatchID string
Attempt int
MaxRetry int
Scheduled bool
Duration time.Duration
Err error
Time time.Time
}
Event is emitted through Observer hooks for queue, worker, and workflow activity. @group Driver Integration
type EventKind ¶
type EventKind string
EventKind identifies a queue runtime event. @group Driver Integration
const ( // EventDispatchStarted indicates public dispatch began. EventDispatchStarted EventKind = "dispatch_started" // EventDispatchSucceeded indicates the backend accepted the public dispatch; synchronous execution may still return an application error. EventDispatchSucceeded EventKind = "dispatch_succeeded" // EventDispatchFailed indicates public dispatch failed before backend acceptance. EventDispatchFailed EventKind = "dispatch_failed" // EventEnqueueAccepted indicates a job was accepted for enqueue. EventEnqueueAccepted EventKind = "enqueue_accepted" // EventEnqueueRejected indicates enqueue failed. EventEnqueueRejected EventKind = "enqueue_rejected" // EventEnqueueDuplicate indicates enqueue was rejected as duplicate. EventEnqueueDuplicate EventKind = "enqueue_duplicate" // EventEnqueueCanceled indicates enqueue was canceled by context. EventEnqueueCanceled EventKind = "enqueue_canceled" // EventProcessStarted indicates a handler started processing. EventProcessStarted EventKind = "process_started" // EventProcessSucceeded indicates a handler completed successfully. EventProcessSucceeded EventKind = "process_succeeded" // EventProcessFailed indicates a handler returned an error or panicked; panics are reported before being rethrown. EventProcessFailed EventKind = "process_failed" // EventProcessRetried indicates processing began for a numbered application retry attempt; redelivery may repeat the fact. EventProcessRetried EventKind = "process_retried" // EventProcessArchived indicates a driver confirmed terminal settlement for a failed attempt. EventProcessArchived EventKind = "process_archived" // EventQueuePaused indicates queue consumption was paused. EventQueuePaused EventKind = "queue_paused" // EventQueueResumed indicates queue consumption was resumed. EventQueueResumed EventKind = "queue_resumed" // EventProcessRecovered indicates SQL bulk recovery requeued one stale in-flight claim without loading its identity fields. EventProcessRecovered EventKind = "process_recovered" // EventRepublishFailed indicates an internal delay/retry republish attempt failed. EventRepublishFailed EventKind = "republish_failed" // EventSettlementFailed indicates delivery finalization or broker settlement failed or remained ambiguous. EventSettlementFailed EventKind = "settlement_failed" // EventJobStarted indicates logical job execution began. EventJobStarted EventKind = "job_started" // EventJobSucceeded indicates logical job execution succeeded. EventJobSucceeded EventKind = "job_succeeded" // EventJobFailed indicates logical job execution reached a failed outcome. EventJobFailed EventKind = "job_failed" // EventChainStarted indicates a chain was created and started. EventChainStarted EventKind = "chain_started" // EventChainAdvanced indicates a chain advanced to its next job. EventChainAdvanced EventKind = "chain_advanced" // EventChainCompleted indicates a chain completed successfully. EventChainCompleted EventKind = "chain_completed" // EventChainFailed indicates a chain reached a failed outcome. EventChainFailed EventKind = "chain_failed" // EventBatchStarted indicates a batch was created and started. EventBatchStarted EventKind = "batch_started" // EventBatchProgressed indicates a batch job reached a terminal outcome. EventBatchProgressed EventKind = "batch_progressed" // EventBatchCompleted indicates a batch completed successfully. EventBatchCompleted EventKind = "batch_completed" // EventBatchFailed indicates a batch reached a failed outcome. EventBatchFailed EventKind = "batch_failed" // EventBatchCancelled indicates remaining batch work was cancelled. EventBatchCancelled EventKind = "batch_cancelled" // EventCallbackStarted indicates an ephemeral workflow callback began. EventCallbackStarted EventKind = "callback_started" // EventCallbackSucceeded indicates an ephemeral workflow callback succeeded. EventCallbackSucceeded EventKind = "callback_succeeded" // EventCallbackFailed indicates an ephemeral workflow callback failed. EventCallbackFailed EventKind = "callback_failed" )
type EventLayer ¶ added in v0.3.0
type EventLayer string
EventLayer identifies the subsystem that committed an observed fact. @group Observability
const ( // EventLayerQueue identifies dispatch, enqueue, and queue-control facts. EventLayerQueue EventLayer = "queue" // EventLayerWorker identifies physical delivery and handler-attempt facts. EventLayerWorker EventLayer = "worker" // EventLayerWorkflow identifies chain, batch, and continuation facts. EventLayerWorkflow EventLayer = "workflow" )
type FailOnError ¶
FailOnError marks selected handler failures as permanent. @group Queue
type FakeQueue ¶
type FakeQueue struct {
// contains filtered or unexported fields
}
FakeQueue is the concurrency-safe queue and workflow fake for tests. @group Testing
func NewFake ¶
func NewFake() *FakeQueue
NewFake creates the canonical fake for direct and workflow tests. @group Testing
Example: fake queue assertions
fake := queue.NewFake()
_ = fake.Dispatch(
queue.NewJob("emails:send").
Payload(map[string]any{"id": 1}).
OnQueue("critical"),
)
records := fake.Records()
fmt.Println(len(records), records[0].Queue, records[0].Job.Type)
// Output: 1 critical emails:send
func (*FakeQueue) AssertBatchCount ¶ added in v0.3.0
AssertBatchCount fails unless the accepted batch count equals expected. @group Testing
Example: assert fake batch count
fake := queue.NewFake()
_, _ = fake.Batch(queue.NewJob("emails:send")).Dispatch(context.Background())
fake.AssertBatchCount(t, 1)
func (*FakeQueue) AssertBatched ¶ added in v0.3.0
func (f *FakeQueue) AssertBatched(t testing.TB, predicate func(BatchRecord) bool)
AssertBatched fails unless an accepted canonical batch matches predicate. The predicate runs outside the recorder lock so it may safely inspect the fake. @group Testing
Example: assert fake batch policy
fake := queue.NewFake()
_, _ = fake.Batch(queue.NewJob("emails:send")).Name("nightly").Dispatch(context.Background())
fake.AssertBatched(t, func(record queue.BatchRecord) bool { return record.Name == "nightly" })
func (*FakeQueue) AssertChained ¶ added in v0.3.0
AssertChained fails unless an accepted chain has the expected ordered job types. @group Testing
Example: assert a fake chain
fake := queue.NewFake()
_, _ = fake.Chain(
queue.NewJob("reports:build"),
queue.NewJob("reports:publish"),
).Dispatch(context.Background())
fake.AssertChained(t, []string{"reports:build", "reports:publish"})
func (*FakeQueue) AssertCount ¶
AssertCount fails when the direct dispatch count is not expected. @group Testing
Example: assert dispatch count
fake := queue.NewFake()
_ = fake.Dispatch(queue.NewJob("emails:send"))
fake.AssertCount(t, 1)
func (*FakeQueue) AssertDispatched ¶
AssertDispatched fails when jobType was not dispatched. @group Testing
Example: assert job type dispatched
fake := queue.NewFake()
_ = fake.Dispatch(queue.NewJob("emails:send"))
fake.AssertDispatched(t, "emails:send")
func (*FakeQueue) AssertDispatchedOn ¶
AssertDispatchedOn fails when jobType was not dispatched on queueName. @group Testing
Example: assert job type dispatched on queue
fake := queue.NewFake()
_ = fake.Dispatch(
queue.NewJob("emails:send").
OnQueue("critical"),
)
fake.AssertDispatchedOn(t, "critical", "emails:send")
func (*FakeQueue) AssertDispatchedTimes ¶
AssertDispatchedTimes fails when jobType dispatch count does not match expected. @group Testing
Example: assert job type dispatched times
fake := queue.NewFake()
_ = fake.Dispatch(queue.NewJob("emails:send"))
_ = fake.Dispatch(queue.NewJob("emails:send"))
fake.AssertDispatchedTimes(t, "emails:send", 2)
func (*FakeQueue) AssertNotDispatched ¶
AssertNotDispatched fails when jobType was dispatched. @group Testing
Example: assert job type not dispatched
fake := queue.NewFake()
_ = fake.Dispatch(queue.NewJob("emails:send"))
fake.AssertNotDispatched(t, "emails:cancel")
func (*FakeQueue) AssertNothingBatched ¶ added in v0.3.0
AssertNothingBatched fails when any accepted batch was recorded. @group Testing
func (*FakeQueue) AssertNothingDispatched ¶
AssertNothingDispatched fails when any direct dispatch was recorded. @group Testing
Example: assert nothing dispatched
fake := queue.NewFake() fake.AssertNothingDispatched(t)
func (*FakeQueue) Batch ¶ added in v0.3.0
func (f *FakeQueue) Batch(jobs ...Job) BatchBuilder
Batch creates a fake batch backed by the production workflow builder and records it only when Dispatch accepts all initial member deliveries. Fluent function callbacks are accepted for compatibility but are not retained in fake runtime state or executed. @group Testing
func (*FakeQueue) BatchRecords ¶ added in v0.3.0
func (f *FakeQueue) BatchRecords() []BatchRecord
BatchRecords returns isolated creation records for accepted fake batches. @group Testing
Example: inspect a fake batch
fake := queue.NewFake()
_, _ = fake.Batch(
queue.NewJob("emails:first"),
queue.NewJob("emails:second"),
).Name("nightly").AllowFailures().Dispatch(context.Background())
record := fake.BatchRecords()[0]
fmt.Println(record.Name, len(record.Jobs), record.AllowFailed)
// Output: nightly 2 true
func (*FakeQueue) BusDispatch ¶
func (f *FakeQueue) BusDispatch(ctx context.Context, jobType string, payload []byte, opts busruntime.JobOptions) error
BusDispatch satisfies the internal orchestration runtime adapter. @group Testing
func (*FakeQueue) BusDispatchDirect ¶ added in v0.3.0
func (f *FakeQueue) BusDispatchDirect(ctx context.Context, jobType string, payload []byte, metadata busruntime.DeliveryMetadata, opts busruntime.JobOptions) error
BusDispatchDirect records the application job and its correlation metadata without introducing the legacy workflow envelope. @group Testing
func (*FakeQueue) BusRegister ¶
func (f *FakeQueue) BusRegister(string, busruntime.Handler)
BusRegister satisfies the internal orchestration runtime adapter. @group Testing
func (*FakeQueue) Chain ¶ added in v0.3.0
func (f *FakeQueue) Chain(jobs ...Job) ChainBuilder
Chain creates a fake chain backed by the production workflow builder and records it only when Dispatch accepts its initial delivery. Fluent function callbacks are accepted for compatibility but are not retained in fake runtime state or executed. @group Testing
func (*FakeQueue) ChainRecords ¶ added in v0.3.0
func (f *FakeQueue) ChainRecords() []ChainRecord
ChainRecords returns isolated creation records for accepted fake chains. @group Testing
Example: inspect a fake chain
fake := queue.NewFake()
_, _ = fake.Chain(
queue.NewJob("reports:build"),
queue.NewJob("reports:publish"),
).OnQueue("workflow").Dispatch(context.Background())
record := fake.ChainRecords()[0]
fmt.Println(len(record.Nodes), record.Queue)
// Output: 2 workflow
func (*FakeQueue) ContinuationRecords ¶ added in v0.3.0
func (f *FakeQueue) ContinuationRecords() []ContinuationRecord
ContinuationRecords returns accepted fake workflow definitions without phantom pending invocations.
func (*FakeQueue) Dispatch ¶
Dispatch records a typed job payload in-memory using the fake default queue. @group Testing
Example: dispatch to fake queue
fake := queue.NewFake()
err := fake.Dispatch(queue.NewJob("emails:send").OnQueue("default"))
_ = err
func (*FakeQueue) Driver ¶
Driver returns the active queue driver. @group Testing
Example: fake driver
fake := queue.NewFake() driver := fake.Driver() _ = driver
func (*FakeQueue) FindBatch ¶ added in v0.3.0
FindBatch returns workflow state created by the fake's production engine. @group Testing
func (*FakeQueue) FindChain ¶ added in v0.3.0
FindChain returns workflow state created by the fake's production engine. @group Testing
func (*FakeQueue) FindContinuations ¶ added in v0.3.0
func (f *FakeQueue) FindContinuations(ctx context.Context, id string) ([]ContinuationOutcome, error)
FindContinuations returns committed triggered fake outcomes independently of definitions.
func (*FakeQueue) Prune ¶ added in v0.3.0
Prune removes terminal workflow state while retaining fake dispatch records. @group Testing
func (*FakeQueue) Ready ¶
Ready validates fake queue readiness. @group Testing
Example: fake ready
fake := queue.NewFake() fmt.Println(fake.Ready(context.Background()) == nil) // Output: true
func (*FakeQueue) Records ¶
func (f *FakeQueue) Records() []DispatchRecord
Records returns isolated records for accepted direct dispatches. Chain and batch creation is available through ChainRecords and BatchRecords. @group Testing
Example: read records
fake := queue.NewFake()
_ = fake.Dispatch(queue.NewJob("emails:send").OnQueue("default"))
records := fake.Records()
fmt.Println(len(records), records[0].Job.Type)
// Output: 1 emails:send
func (*FakeQueue) Register ¶
Register is a compatibility no-op because the recording fake never executes handlers. @group Testing
Example: register no-op on fake
fake := queue.NewFake()
fake.Register("emails:send", func(context.Context, queue.Job) error { return nil })
func (*FakeQueue) Reset ¶
func (f *FakeQueue) Reset()
Reset clears direct dispatches and all workflow records through every fake view. @group Testing
Example: reset records
fake := queue.NewFake()
_ = fake.Dispatch(queue.NewJob("emails:send").OnQueue("default"))
fmt.Println(len(fake.Records()))
fake.Reset()
fmt.Println(len(fake.Records()))
// Output:
// 1
// 0
func (*FakeQueue) Shutdown ¶
Shutdown is a compatibility no-op because the recording fake owns no worker resources. @group Testing
Example: shutdown fake queue
fake := queue.NewFake() err := fake.Shutdown(context.Background()) _ = err
func (*FakeQueue) StartWorkers ¶
StartWorkers is a compatibility no-op because the recording fake owns no workers. @group Testing
Example: start fake workers
fake := queue.NewFake() err := fake.StartWorkers(context.Background()) _ = err
func (*FakeQueue) WithContext ¶ added in v0.1.12
WithContext returns a derived fake queue handle bound to ctx. @group Testing
type Handler ¶
Handler processes a job. @group Job
Example: handler
handler := func(ctx context.Context, job queue.Job) error { return nil }
_ = handler
type Job ¶
type Job struct {
Type string
// contains filtered or unexported fields
}
Job is a pure queue payload value plus enqueue metadata. @group Job
Example: job
job := queue.NewJob("emails:send").
PayloadJSON(map[string]string{"to": "user@example.com"}).
OnQueue("critical")
_ = job
func DriverWithAttempt ¶
DriverWithAttempt returns a copy of the job with the attempt number set.
This is an advanced helper intended for driver-module implementations. @group Driver Integration
func DriverWithMetadata ¶ added in v0.3.0
func DriverWithMetadata(job Job, metadata DriverJobMetadata) Job
DriverWithMetadata returns a job carrying supported direct-delivery correlation. Unknown versions are ignored while the application payload and delivery policy remain usable.
This is an advanced helper intended for driver-module implementations. @group Driver Integration
func NewJob ¶
NewJob creates a job value with a required job type. @group Job
Example: new job
job := queue.NewJob("emails:send")
_ = job
func (Job) Backoff ¶
Backoff sets delay between retries. @group Job
Example: backoff
job := queue.NewJob("emails:send").Backoff(500 * time.Millisecond)
_ = job
func (Job) Bind ¶
Bind unmarshals job payload JSON into dst. @group Job
Example: bind payload
type EmailPayload struct {
ID int `json:"id"`
To string `json:"to"`
}
job := queue.NewJob("emails:send").Payload(EmailPayload{
ID: 1,
To: "user@example.com",
})
var payload EmailPayload
if err := job.Bind(&payload); err != nil {
return
}
_ = payload.To
func (Job) Delay ¶
Delay defers execution by duration. @group Job
Example: delay
job := queue.NewJob("emails:send").Delay(300 * time.Millisecond)
_ = job
func (Job) OnQueue ¶
OnQueue sets the target queue name. @group Job
Example: on queue
job := queue.NewJob("emails:send").OnQueue("critical")
_ = job
func (Job) Payload ¶
Payload sets job payload from common value types. @group Job
Example: payload bytes
jobBytes := queue.NewJob("emails:send").Payload([]byte(`{"id":1}`))
_ = jobBytes
Example: payload struct
type Meta struct {
Nested bool `json:"nested"`
}
type EmailPayload struct {
ID int `json:"id"`
To string `json:"to"`
Meta Meta `json:"meta"`
}
jobStruct := queue.NewJob("emails:send").Payload(EmailPayload{
ID: 1,
To: "user@example.com",
Meta: Meta{Nested: true},
})
_ = jobStruct
Example: payload map
jobMap := queue.NewJob("emails:send").Payload(map[string]any{
"id": 1,
"to": "user@example.com",
"meta": map[string]any{"nested": true},
})
_ = jobMap
func (Job) PayloadAs ¶ added in v0.3.0
PayloadAs unmarshals the job payload JSON and returns it as T. @group Job
Example: typed job payload
type EmailPayload struct {
To string `json:"to"`
}
job := queue.NewJob("emails:send").Payload(EmailPayload{To: "user@example.com"})
payload, err := job.PayloadAs[EmailPayload]()
fmt.Println(err == nil, payload.To)
// true user@example.com
func (Job) PayloadBytes ¶
PayloadBytes returns a copy of job payload bytes. @group Job
Example: payload bytes read
job := queue.NewJob("emails:send").Payload([]byte(`{"id":1}`))
payload := job.PayloadBytes()
_ = payload
func (Job) PayloadJSON ¶
PayloadJSON marshals payload as JSON. @group Job
Example: payload json
job := queue.NewJob("emails:send").PayloadJSON(map[string]int{"id": 1})
_ = job
func (Job) Retry ¶
Retry sets max retry attempts. @group Job
Example: retry
job := queue.NewJob("emails:send").Retry(4)
_ = job
type JobSnapshot ¶
type JobSnapshot struct {
ID string
Queue string
State JobState
Type string
Payload string
Attempt int
MaxRetry int
LastError string
NextProcessAt *time.Time
CompletedAt *time.Time
}
JobSnapshot describes an admin-facing queue job record. @group Admin
type JobState ¶
type JobState string
JobState identifies queue job state used by queue admin APIs. @group Admin
type ListJobsOptions ¶
ListJobsOptions configures queue admin list jobs calls. @group Admin
func (ListJobsOptions) Normalize ¶
func (o ListJobsOptions) Normalize() ListJobsOptions
Normalize returns a safe options payload with defaults applied. @group Admin
Example: normalize list options
opts := queue.ListJobsOptions{Queue: "", State: "", Page: 0, PageSize: 1000}
normalized := opts.Normalize()
fmt.Println(normalized.Queue, normalized.State, normalized.Page, normalized.PageSize)
// Output: default pending 1 500
type ListJobsResult ¶
type ListJobsResult struct {
Jobs []JobSnapshot
Total int64
}
ListJobsResult contains queue admin job listing output. @group Admin
func ListJobs ¶
func ListJobs(ctx context.Context, q any, opts ListJobsOptions) (ListJobsResult, error)
ListJobs lists jobs for a queue and state when supported. @group Admin
Example: list jobs via helper
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
_, err = queue.ListJobs(context.Background(), q, queue.ListJobsOptions{
Queue: "default",
State: queue.JobStatePending,
})
_ = err
type Lock ¶
type Lock interface {
// Release relinquishes the acquired lease.
Release(ctx context.Context) error
}
Lock represents an acquired overlap-prevention lease. @group Queue
type Locker ¶
type Locker interface {
// Acquire attempts to hold key for ttl.
Acquire(ctx context.Context, key string, ttl time.Duration) (Lock, bool, error)
}
Locker acquires keyed leases for overlap prevention. @group Queue
type Logger ¶
type Logger interface {
Debug(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
Fatal(args ...interface{})
}
Logger is a generic runtime logger contract that drivers may use to surface their internal worker/server lifecycle output.
type Message ¶
type Message struct {
SchemaVersion int
DispatchID string
JobID string
ChainID string
BatchID string
Attempt int
JobType string
// contains filtered or unexported fields
}
Message is the delivered logical job message passed to queue handlers and middleware. Its exported fields carry workflow correlation metadata while its payload remains isolated behind PayloadBytes and Bind. @group Queue
func NewMessage ¶ added in v0.3.0
NewMessage creates a logical queue message from an application job type and exact payload bytes. The payload is copied so callers can safely reuse or mutate their input buffer. @group Constructors
func (Message) Continuation ¶ added in v0.3.0
func (m Message) Continuation() (Continuation, bool)
Continuation returns immutable invocation metadata when this message is a durable hook.
func (Message) PayloadAs ¶ added in v0.3.0
PayloadAs unmarshals the delivered payload and returns it as T. @group Queue
Example: typed message payload
type EmailPayload struct {
To string `json:"to"`
}
message := queue.NewMessage("emails:send", []byte(`{"to":"user@example.com"}`))
payload, err := message.PayloadAs[EmailPayload]()
fmt.Println(err == nil, payload.To)
// true user@example.com
func (Message) PayloadBytes ¶ added in v0.3.0
PayloadBytes returns an isolated copy of the raw job payload. @group Queue
type Middleware ¶
type Middleware interface {
// Handle wraps the remaining middleware and handler chain.
Handle(ctx context.Context, message Message, next Next) error
}
Middleware intercepts logical queue job execution. @group Queue
type MiddlewareFunc ¶
MiddlewareFunc adapts a function to Middleware. @group Queue
type NoopLogger ¶
type NoopLogger struct{}
NoopLogger disables driver-managed internal logs when passed through config.
func (NoopLogger) Debug ¶
func (NoopLogger) Debug(...interface{})
func (NoopLogger) Error ¶
func (NoopLogger) Error(...interface{})
func (NoopLogger) Fatal ¶
func (NoopLogger) Fatal(...interface{})
func (NoopLogger) Info ¶
func (NoopLogger) Info(...interface{})
func (NoopLogger) Warn ¶
func (NoopLogger) Warn(...interface{})
type ObservedJobMetadata ¶ added in v0.3.0
type ObservedJobMetadata struct {
JobType string
JobKey string
DispatchID string
JobID string
ChainID string
BatchID string
}
ObservedJobMetadata contains application identity and correlation resolved from direct driver metadata or a legacy internal delivery envelope. JobKey groups the same logical type and payload used by UniqueFor without becoming its persisted, queue-scoped key. @group Driver Integration
func ResolveObservedJobMetadata ¶ added in v0.3.0
func ResolveObservedJobMetadata(rawType string, payload []byte) ObservedJobMetadata
ResolveObservedJobMetadata bridges legacy versioned workflow envelopes into the event model. Direct-aware drivers should use ResolveObservedJobMetadataFromJob. Malformed, unknown-version, and non-internal payloads remain observable as their raw physical job. @group Driver Integration
func ResolveObservedJobMetadataFromJob ¶ added in v0.3.0
func ResolveObservedJobMetadataFromJob(job Job) ObservedJobMetadata
ResolveObservedJobMetadataFromJob returns correlation from the direct driver metadata channel when present and otherwise decodes a legacy workflow delivery.
This is an advanced helper intended for optional driver integrations. @group Driver Integration
type Observer ¶
type Observer interface {
// Observe handles a queue runtime event.
// @group Observability
//
// Example: observe runtime event
//
// var observer queue.Observer
// observer.Observe(context.Background(), queue.Event{
// Kind: queue.EventEnqueueAccepted,
// Driver: queue.DriverSync,
// Queue: "default",
// })
Observe(ctx context.Context, event Event)
}
Observer receives queue, worker, and workflow events. Implementations must be safe for concurrent calls from dispatchers and workers. @group Observability
func MultiObserver ¶
MultiObserver fans out events to multiple observers. @group Observability
Example: fan out to multiple observers
events := make(chan queue.Event, 2)
observer := queue.MultiObserver(
queue.ChannelObserver{Events: events},
queue.ObserverFunc(func(context.Context, queue.Event) {}),
)
observer.Observe(context.Background(), queue.Event{Kind: queue.EventEnqueueAccepted})
fmt.Println(len(events))
// Output: 1
type ObserverFunc ¶
ObserverFunc adapts a function to an Observer. @group Observability
func (ObserverFunc) Observe ¶
func (f ObserverFunc) Observe(ctx context.Context, event Event)
Observe calls the wrapped function. @group Observability
Example: observer func logging hook
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
observer := queue.ObserverFunc(func(ctx context.Context, event queue.Event) {
logger.Info("queue event",
"kind", event.Kind,
"driver", event.Driver,
"queue", event.Queue,
"job_type", event.JobType,
"attempt", event.Attempt,
"max_retry", event.MaxRetry,
"duration", event.Duration,
"err", event.Err,
)
})
observer.Observe(context.Background(), queue.Event{
Kind: queue.EventProcessSucceeded,
Driver: queue.DriverSync,
Queue: "default",
JobType: "emails:send",
})
type Option ¶
type Option func(*runtimeOptions)
Option configures the high-level queue and workflow runtime. @group Queue
func WithClock ¶
WithClock overrides the workflow runtime clock. @group Queue
Example: workflow clock
q, err := queue.New(
queue.Config{Driver: queue.DriverSync},
queue.WithClock(func() time.Time { return time.Unix(0, 0) }),
)
if err != nil {
return
}
_ = q
func WithHandlerContextDecorator ¶ added in v0.1.14
WithHandlerContextDecorator decorates queue handler execution context before process lifecycle events and handler execution run. @group Queue
Example: decorate handler context
q, err := queue.New(
queue.Config{Driver: queue.DriverSync},
queue.WithHandlerContextDecorator(func(ctx context.Context) context.Context {
return context.WithValue(ctx, "source", "jobs")
}),
)
if err != nil {
return
}
_ = q
func WithLegacyDirectEnvelope ¶ added in v0.3.0
func WithLegacyDirectEnvelope() Option
WithLegacyDirectEnvelope keeps ordinary dispatches on the version-one `bus:job` wire route during a workers-first migration. Remove this option only after every consumer can process canonical direct deliveries. See the [direct delivery migration guide] for backend-specific rollout and rollback.
[direct delivery migration guide]: https://github.com/goforj/queue/blob/main/docs/direct-delivery-migration.md @group Queue
func WithMiddleware ¶
func WithMiddleware(middlewares ...Middleware) Option
WithMiddleware appends queue workflow middleware. @group Queue
Example: middleware
mw := queue.MiddlewareFunc(func(ctx context.Context, m queue.Message, next queue.Next) error {
return next(ctx, m)
})
q, err := queue.New(queue.Config{Driver: queue.DriverSync}, queue.WithMiddleware(mw))
if err != nil {
return
}
_ = q
func WithObserver ¶
WithObserver installs one observer for queue, worker, and workflow lifecycle events. @group Queue
Example: observe all queue activity
observer := queue.ObserverFunc(func(_ context.Context, event queue.Event) {
_ = event.Kind
})
q, err := queue.New(queue.Config{Driver: queue.DriverSync}, queue.WithObserver(observer))
if err != nil {
return
}
_ = q
func WithResourceID ¶ added in v0.3.0
WithResourceID supplies the stable resource scope used by durable built-in continuation recovery. Use the same value across consumers of one queue and distinct values for independent resources sharing a store.
func WithStore ¶
func WithStore(store WorkflowStore) Option
WithStore overrides the workflow orchestration store. @group Queue
Example: workflow store
var store queue.WorkflowStore
q, err := queue.New(queue.Config{Driver: queue.DriverSync}, queue.WithStore(store))
if err != nil {
return
}
_ = q
func WithWorkers ¶
WithWorkers sets desired worker concurrency before StartWorkers. It applies to high-level queue constructors (for example NewWorkerpool/New/NewSync). @group Queue
Example: constructor workers option
q, err := queue.NewWorkerpool(
queue.WithWorkers(4), // optional; default: runtime.NumCPU() (min 1)
)
if err != nil {
return
}
_ = q
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is the high-level user-facing queue API. It composes shared job execution with the internal workflow coordinator. @group Queue
func New ¶
New creates the high-level Queue API based on Config.Driver. @group Constructors
Example: create a queue and dispatch a workflow-capable job
q, err := queue.New(queue.Config{Driver: queue.DriverWorkerpool})
if err != nil {
return
}
type EmailPayload struct {
ID int `json:"id"`
}
q.Register("emails:send", func(ctx context.Context, m queue.Message) error {
var payload EmailPayload
if err := m.Bind(&payload); err != nil {
return err
}
_ = payload
return nil
})
_ = q.WithWorkers(1).StartWorkers(context.Background()) // optional; default: runtime.NumCPU() (min 1)
defer q.Shutdown(context.Background())
_, _ = q.Dispatch(
queue.NewJob("emails:send").
Payload(EmailPayload{ID: 1}).
OnQueue("default"),
)
func NewNull ¶
NewNull creates a Queue on the null backend. @group Constructors
Example: null backend
q, err := queue.NewNull()
if err != nil {
return
}
_ = q
func NewSync ¶
NewSync creates a Queue on the synchronous in-process backend. @group Constructors
Example: sync backend
q, err := queue.NewSync()
if err != nil {
return
}
_ = q
func NewWorkerpool ¶
NewWorkerpool creates a Queue on the in-process workerpool backend. @group Constructors
Example: workerpool backend
q, err := queue.NewWorkerpool()
if err != nil {
return
}
_ = q
func (*Queue) Batch ¶
func (r *Queue) Batch(jobs ...Job) BatchBuilder
Batch creates a batch builder for fan-out workflow execution. @group Queue
Example: batch
q, err := queue.NewSync()
if err != nil {
return
}
q.Register("emails:send", func(ctx context.Context, m queue.Message) error { return nil })
if err := q.StartWorkers(context.Background()); err != nil {
return
}
defer q.Shutdown(context.Background())
_, _ = q.Batch(
queue.NewJob("emails:send").Payload(map[string]any{"id": 1}),
queue.NewJob("emails:send").Payload(map[string]any{"id": 2}),
).Name("send-emails").OnQueue("default").Dispatch(context.Background())
func (*Queue) CancelJob ¶
CancelJob cancels a job via queue admin capability when supported. @group Admin
Example: queue method cancel job
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
if !queue.SupportsQueueAdmin(q) {
return
}
err = q.CancelJob(context.Background(), "job-id")
_ = err
func (*Queue) Chain ¶
func (r *Queue) Chain(jobs ...Job) ChainBuilder
Chain creates a chain builder for sequential workflow execution. @group Queue
Example: chain
q, err := queue.NewSync()
if err != nil {
return
}
q.Register("first", func(ctx context.Context, m queue.Message) error { return nil })
q.Register("second", func(ctx context.Context, m queue.Message) error { return nil })
if err := q.StartWorkers(context.Background()); err != nil {
return
}
defer q.Shutdown(context.Background())
_, _ = q.Chain(
queue.NewJob("first"),
queue.NewJob("second"),
).OnQueue("default").Dispatch(context.Background())
func (*Queue) ClearQueue ¶
ClearQueue clears queue jobs via queue admin capability when supported. @group Admin
Example: queue method clear queue
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
if !queue.SupportsQueueAdmin(q) {
return
}
err = q.ClearQueue(context.Background(), "default")
_ = err
func (*Queue) DeleteJob ¶
DeleteJob deletes a job via queue admin capability when supported. @group Admin
Example: queue method delete job
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
if !queue.SupportsQueueAdmin(q) {
return
}
err = q.DeleteJob(context.Background(), "default", "job-id")
_ = err
func (*Queue) Dispatch ¶
func (r *Queue) Dispatch(job Job) (DispatchResult, error)
Dispatch enqueues a high-level job using its application type and exact payload bytes together with the queue's bound context. @group Queue
Example: dispatch
q, err := queue.NewSync()
if err != nil {
return
}
q.Register("emails:send", func(ctx context.Context, m queue.Message) error { return nil })
if err := q.StartWorkers(context.Background()); err != nil {
return
}
defer q.Shutdown(context.Background())
job := queue.NewJob("emails:send").Payload(map[string]any{"id": 1}).OnQueue("default")
_, _ = q.Dispatch(job)
func (*Queue) Driver ¶
Driver reports the configured backend driver for the underlying queue runtime. @group Queue
Example: driver
q, err := queue.NewSync()
if err != nil {
return
}
fmt.Println(q.Driver())
// Output: sync
func (*Queue) FindBatch ¶
FindBatch returns current batch state by ID. @group Queue
Example: find batch
q, err := queue.NewSync()
if err != nil {
return
}
q.Register("emails:send", func(ctx context.Context, m queue.Message) error { return nil })
batchID, err := q.Batch(queue.NewJob("emails:send")).Dispatch(context.Background())
if err != nil {
return
}
_, _ = q.FindBatch(context.Background(), batchID)
func (*Queue) FindChain ¶
FindChain returns current chain state by ID. @group Queue
Example: find chain
q, err := queue.NewSync()
if err != nil {
return
}
q.Register("first", func(ctx context.Context, m queue.Message) error { return nil })
chainID, err := q.Chain(queue.NewJob("first")).Dispatch(context.Background())
if err != nil {
return
}
_, _ = q.FindChain(context.Background(), chainID)
func (*Queue) FindContinuations ¶ added in v0.3.0
FindContinuations returns triggered invocation outcomes, including scheduled but unsettled work.
func (*Queue) History ¶
func (r *Queue) History(ctx context.Context, queueName string, window QueueHistoryWindow) ([]QueueHistoryPoint, error)
History returns queue history points via queue admin capability when supported. @group Admin
Example: queue method history
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
points, err := q.History(context.Background(), "default", queue.QueueHistoryHour)
_ = points
_ = err
func (*Queue) ListJobs ¶
func (r *Queue) ListJobs(ctx context.Context, opts ListJobsOptions) (ListJobsResult, error)
ListJobs lists jobs via queue admin capability when supported. @group Admin
Example: queue method list jobs
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
_, err = q.ListJobs(context.Background(), queue.ListJobsOptions{
Queue: "default",
State: queue.JobStatePending,
})
_ = err
func (*Queue) Pause ¶
Pause pauses consumption for a queue when supported by the underlying driver. See the README "Queue Backends" table for Pause/Resume support and docs/backend-guarantees.md (Capability Matrix) for broader backend differences. @group Queue
Example: pause queue
q, err := queue.NewSync()
if err != nil {
return
}
if queue.SupportsPause(q) {
_ = q.Pause(context.Background(), "default")
}
func (*Queue) Prune ¶
Prune deletes old workflow state records. @group Queue
Example: prune workflow state
q, err := queue.NewSync()
if err != nil {
return
}
_ = q.Prune(context.Background(), time.Now().Add(-24*time.Hour))
func (*Queue) Ready ¶
Ready validates queue backend readiness for dispatch/worker operation. @group Queue
Example: queue ready
q, err := queue.NewSync()
if err != nil {
return
}
fmt.Println(q.Ready(context.Background()) == nil)
// true
func (*Queue) Register ¶
Register binds a handler for a high-level job type. @group Queue
Example: register
q, err := queue.NewSync()
if err != nil {
return
}
type EmailPayload struct {
ID int `json:"id"`
}
q.Register("emails:send", func(ctx context.Context, m queue.Message) error {
var payload EmailPayload
if err := m.Bind(&payload); err != nil {
return err
}
_ = payload
return nil
})
func (*Queue) Resume ¶
Resume resumes consumption for a queue when supported by the underlying driver. @group Queue
Example: resume queue
q, err := queue.NewSync()
if err != nil {
return
}
if queue.SupportsPause(q) {
_ = q.Resume(context.Background(), "default")
}
func (*Queue) RetryJob ¶
RetryJob retries (runs now) a job via queue admin capability when supported. @group Admin
Example: queue method retry job
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
if !queue.SupportsQueueAdmin(q) {
return
}
err = q.RetryJob(context.Background(), "default", "job-id")
_ = err
func (*Queue) Run ¶
Run starts worker processing, blocks until ctx is canceled, then gracefully shuts down. @group Queue
Example: run until canceled
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
q, err := queue.NewWorkerpool()
if err != nil {
return
}
q.Register("emails:send", func(ctx context.Context, m queue.Message) error { return nil })
go func() {
time.Sleep(100 * time.Millisecond)
cancel()
}()
_ = q.Run(ctx)
func (*Queue) Shutdown ¶
Shutdown drains workers and closes underlying resources. @group Queue
Example: shutdown
q, err := queue.NewWorkerpool()
if err != nil {
return
}
_ = q.StartWorkers(context.Background())
_ = q.Shutdown(context.Background())
func (*Queue) StartWorkers ¶
StartWorkers starts worker processing. @group Queue
Example: start workers
q, err := queue.NewWorkerpool()
if err != nil {
return
}
_ = q.StartWorkers(context.Background())
func (*Queue) Stats ¶
func (r *Queue) Stats(ctx context.Context) (StatsSnapshot, error)
Stats returns a normalized snapshot when supported by the underlying driver. @group Queue
Example: stats
q, err := queue.NewSync()
if err != nil {
return
}
if queue.SupportsNativeStats(q) {
_, _ = q.Stats(context.Background())
}
func (*Queue) WithContext ¶ added in v0.1.12
WithContext returns a derived queue handle bound to ctx. @group Queue
func (*Queue) WithWorkers ¶
WithWorkers sets desired worker concurrency before StartWorkers. @group Queue
Example: workers
q, err := queue.NewWorkerpool()
if err != nil {
return
}
q.WithWorkers(4) // optional; default: runtime.NumCPU() (min 1)
type QueueAdmin ¶
type QueueAdmin interface {
ListJobs(ctx context.Context, opts ListJobsOptions) (ListJobsResult, error)
RetryJob(ctx context.Context, queueName, jobID string) error
CancelJob(ctx context.Context, jobID string) error
DeleteJob(ctx context.Context, queueName, jobID string) error
ClearQueue(ctx context.Context, queueName string) error
History(ctx context.Context, queueName string, window QueueHistoryWindow) ([]QueueHistoryPoint, error)
}
QueueAdmin exposes optional queue admin capabilities. @group Admin
type QueueController ¶
type QueueController interface {
Pause(ctx context.Context, queueName string) error
Resume(ctx context.Context, queueName string) error
}
QueueController exposes queue pause/resume controls. @group Observability
type QueueCounters ¶
type QueueCounters struct {
Pending int64
Active int64
Scheduled int64
Retry int64
Archived int64
Processed int64
Failed int64
Paused int64
AvgWait time.Duration
AvgRun time.Duration
}
QueueCounters exposes normalized queue counters collected from events. @group Observability
type QueueHistoryPoint ¶
QueueHistoryPoint represents processed/failed totals at a point in time. @group Admin
func QueueHistory ¶
func QueueHistory(ctx context.Context, q any, queueName string, window QueueHistoryWindow) ([]QueueHistoryPoint, error)
QueueHistory returns queue history points when supported. @group Admin
Example: history via helper
q, err := redisqueue.New("127.0.0.1:6379")
if err != nil {
return
}
_, err = queue.QueueHistory(context.Background(), q, "default", queue.QueueHistoryHour)
_ = err
func SinglePointHistory ¶
func SinglePointHistory(snapshot StatsSnapshot, queueName string) []QueueHistoryPoint
SinglePointHistory converts a snapshot into a single current-history point. This helper is intended for driver modules that do not expose historical buckets. @group Admin
Example: single-point history
snapshot := queue.StatsSnapshot{
ByQueue: map[string]queue.QueueCounters{
"default": {Processed: 12, Failed: 1},
},
}
points := queue.SinglePointHistory(snapshot, "default")
fmt.Println(len(points), points[0].Processed, points[0].Failed)
// Output: 1 12 1
func TimelineHistoryFromSnapshot ¶
func TimelineHistoryFromSnapshot(snapshot StatsSnapshot, queueName string, window QueueHistoryWindow) []QueueHistoryPoint
TimelineHistoryFromSnapshot records queue counters and returns windowed points. This is intended for drivers that don't expose native multi-point history. @group Admin
Example: timeline history from snapshots
snapshot := queue.StatsSnapshot{
ByQueue: map[string]queue.QueueCounters{
"default": {Processed: 5, Failed: 1},
},
}
points := queue.TimelineHistoryFromSnapshot(snapshot, "default", queue.QueueHistoryHour)
fmt.Println(len(points) >= 1)
// Output: true
type QueueHistoryProvider ¶
type QueueHistoryProvider interface {
History(ctx context.Context, queueName string, window QueueHistoryWindow) ([]QueueHistoryPoint, error)
}
QueueHistoryProvider exposes queue history capability independently from full queue admin support. Drivers like sync/workerpool can provide history without supporting per-job admin operations. @group Admin
type QueueHistoryWindow ¶
type QueueHistoryWindow string
QueueHistoryWindow identifies queue history horizon. @group Admin
const ( QueueHistoryHour QueueHistoryWindow = "hour" QueueHistoryDay QueueHistoryWindow = "day" QueueHistoryWeek QueueHistoryWindow = "week" )
type QueueThroughput ¶
type QueueThroughput struct {
Hour ThroughputWindow
Day ThroughputWindow
Week ThroughputWindow
}
QueueThroughput contains rolling throughput windows for a queue. @group Observability
type RateLimit ¶
type RateLimit struct {
Key func(ctx context.Context, message Message) string
Limiter RateLimiter
}
RateLimit applies a RateLimiter before handler execution. @group Queue
type RateLimiter ¶
type RateLimiter interface {
// Allow returns whether key may execute and any suggested retry delay.
Allow(ctx context.Context, key string) (allowed bool, retryAfter time.Duration, err error)
}
RateLimiter decides whether a logical key may execute now. @group Queue
type RetryPolicy ¶
type RetryPolicy struct{}
RetryPolicy leaves retry ownership to the underlying worker runtime. @group Queue
type SQLStoreConfig ¶ added in v0.3.0
type SQLStoreConfig struct {
DB *sql.DB
DriverName string
DSN string
// AutoMigrate is retained for source compatibility. NewSQLStore keeps
// startup schema creation enabled regardless of the false zero value; use
// NewSQLStoreWithManagedSchema when deployment tooling owns the schema.
AutoMigrate bool
}
SQLStoreConfig configures connection ownership, dialect binding, and schema setup for a SQL workflow store. @group Queue
type StatsCollector ¶
type StatsCollector struct {
// contains filtered or unexported fields
}
StatsCollector aggregates normalized counters from Observer events. @group Observability
func NewStatsCollector ¶
func NewStatsCollector() *StatsCollector
NewStatsCollector creates an event collector for queue counters. @group Constructors
Example: new stats collector
collector := queue.NewStatsCollector() _ = collector
func (*StatsCollector) Observe ¶
func (c *StatsCollector) Observe(ctx context.Context, event Event)
Observe records an event and updates normalized counters. @group Observability
Example: observe event
collector := queue.NewStatsCollector()
collector.Observe(context.Background(), queue.Event{
Kind: queue.EventEnqueueAccepted,
Driver: queue.DriverSync,
Queue: "default",
Time: time.Now(),
})
func (*StatsCollector) Snapshot ¶
func (c *StatsCollector) Snapshot() StatsSnapshot
Snapshot returns a copy of collected counters. @group Observability
Example: snapshot print
collector := queue.NewStatsCollector()
collector.Observe(context.Background(), queue.Event{
Kind: queue.EventEnqueueAccepted,
Driver: queue.DriverSync,
Queue: "default",
Time: time.Now(),
})
collector.Observe(context.Background(), queue.Event{
Kind: queue.EventProcessStarted,
Driver: queue.DriverSync,
Queue: "default",
JobKey: "job-1",
Time: time.Now(),
})
collector.Observe(context.Background(), queue.Event{
Kind: queue.EventProcessSucceeded,
Driver: queue.DriverSync,
Queue: "default",
JobKey: "job-1",
Duration: 12 * time.Millisecond,
Time: time.Now(),
})
snapshot := collector.Snapshot()
counters, _ := snapshot.Queue("default")
throughput, _ := snapshot.Throughput("default")
fmt.Printf("queues=%v\n", snapshot.Queues())
fmt.Printf("counters=%+v\n", counters)
fmt.Printf("hour=%+v\n", throughput.Hour)
// Output:
// queues=[default]
// counters={Pending:0 Active:0 Scheduled:0 Retry:0 Archived:0 Processed:1 Failed:0 Paused:0 AvgWait:0s AvgRun:12ms}
// hour={Processed:1 Failed:0}
type StatsProvider ¶
type StatsProvider interface {
Stats(ctx context.Context) (StatsSnapshot, error)
}
StatsProvider exposes driver-native queue snapshots. @group Observability
type StatsSnapshot ¶
type StatsSnapshot struct {
ByQueue map[string]QueueCounters
ThroughputByQueue map[string]QueueThroughput
}
StatsSnapshot is a point-in-time view of counters by queue. @group Observability
func Snapshot ¶
func Snapshot(ctx context.Context, q any, collector *StatsCollector) (StatsSnapshot, error)
Snapshot returns driver-native stats, falling back to collector data. @group Observability
Example: snapshot from queue runtime
q, _ := queue.NewSync()
snapshot, _ := q.Stats(context.Background())
_, ok := snapshot.Queue("default")
fmt.Println(ok)
// Output: true
func (StatsSnapshot) Active ¶
func (s StatsSnapshot) Active(name string) int64
Active returns active count for a queue. @group Observability
Example: active count getter
snapshot := queue.StatsSnapshot{
ByQueue: map[string]queue.QueueCounters{
"default": {Active: 2},
},
}
fmt.Println(snapshot.Active("default"))
// Output: 2
func (StatsSnapshot) Archived ¶
func (s StatsSnapshot) Archived(name string) int64
Archived returns archived count for a queue. @group Observability
Example: archived count getter
snapshot := queue.StatsSnapshot{
ByQueue: map[string]queue.QueueCounters{
"default": {Archived: 7},
},
}
fmt.Println(snapshot.Archived("default"))
// Output: 7
func (StatsSnapshot) Failed ¶
func (s StatsSnapshot) Failed(name string) int64
Failed returns failed count for a queue. @group Observability
Example: failed count getter
snapshot := queue.StatsSnapshot{
ByQueue: map[string]queue.QueueCounters{
"default": {Failed: 2},
},
}
fmt.Println(snapshot.Failed("default"))
// Output: 2
func (StatsSnapshot) Paused ¶
func (s StatsSnapshot) Paused(name string) int64
Paused returns the observed pause state for a queue as zero or one. @group Observability
Example: pause state getter
collector := queue.NewStatsCollector()
collector.Observe(context.Background(), queue.Event{
Kind: queue.EventQueuePaused,
Driver: queue.DriverSync,
Queue: "default",
Time: time.Now(),
})
snapshot := collector.Snapshot()
fmt.Println(snapshot.Paused("default"))
// Output: 1
func (StatsSnapshot) Pending ¶
func (s StatsSnapshot) Pending(name string) int64
Pending returns pending count for a queue. @group Observability
Example: pending count getter
snapshot := queue.StatsSnapshot{
ByQueue: map[string]queue.QueueCounters{
"default": {Pending: 3},
},
}
fmt.Println(snapshot.Pending("default"))
// Output: 3
func (StatsSnapshot) Processed ¶
func (s StatsSnapshot) Processed(name string) int64
Processed returns processed count for a queue. @group Observability
Example: processed count getter
snapshot := queue.StatsSnapshot{
ByQueue: map[string]queue.QueueCounters{
"default": {Processed: 11},
},
}
fmt.Println(snapshot.Processed("default"))
// Output: 11
func (StatsSnapshot) Queue ¶
func (s StatsSnapshot) Queue(name string) (QueueCounters, bool)
Queue returns queue counters for a queue name. @group Observability
Example: queue counters getter
collector := queue.NewStatsCollector()
collector.Observe(context.Background(), queue.Event{
Kind: queue.EventEnqueueAccepted,
Driver: queue.DriverSync,
Queue: "default",
Time: time.Now(),
})
snapshot := collector.Snapshot()
counters, ok := snapshot.Queue("default")
fmt.Println(ok, counters.Pending)
// Output: true 1
func (StatsSnapshot) Queues ¶
func (s StatsSnapshot) Queues() []string
Queues returns sorted queue names present in the snapshot. @group Observability
Example: list queues
collector := queue.NewStatsCollector()
collector.Observe(context.Background(), queue.Event{
Kind: queue.EventEnqueueAccepted,
Driver: queue.DriverSync,
Queue: "critical",
Time: time.Now(),
})
snapshot := collector.Snapshot()
names := snapshot.Queues()
fmt.Println(len(names), names[0])
// Output: 1 critical
func (StatsSnapshot) RetryCount ¶
func (s StatsSnapshot) RetryCount(name string) int64
RetryCount returns retry count for a queue. @group Observability
Example: retry count getter
snapshot := queue.StatsSnapshot{
ByQueue: map[string]queue.QueueCounters{
"default": {Retry: 1},
},
}
fmt.Println(snapshot.RetryCount("default"))
// Output: 1
func (StatsSnapshot) Scheduled ¶
func (s StatsSnapshot) Scheduled(name string) int64
Scheduled returns scheduled count for a queue. @group Observability
Example: scheduled count getter
snapshot := queue.StatsSnapshot{
ByQueue: map[string]queue.QueueCounters{
"default": {Scheduled: 4},
},
}
fmt.Println(snapshot.Scheduled("default"))
// Output: 4
func (StatsSnapshot) Throughput ¶
func (s StatsSnapshot) Throughput(name string) (QueueThroughput, bool)
Throughput returns rolling throughput windows for a queue name. @group Observability
Example: throughput getter
collector := queue.NewStatsCollector()
collector.Observe(context.Background(), queue.Event{
Kind: queue.EventProcessSucceeded,
Driver: queue.DriverSync,
Queue: "default",
Time: time.Now(),
})
snapshot := collector.Snapshot()
throughput, ok := snapshot.Throughput("default")
fmt.Printf("ok=%v hour=%+v day=%+v week=%+v\n", ok, throughput.Hour, throughput.Day, throughput.Week)
// Output: ok=true hour={Processed:1 Failed:0} day={Processed:1 Failed:0} week={Processed:1 Failed:0}
type StoredJob ¶ added in v0.3.0
type StoredJob struct {
Type string `json:"type"`
Payload []byte `json:"payload"`
Options StoredJobOptions `json:"options"`
}
StoredJob is the stable logical-job shape persisted inside workflow records. @group Queue
type StoredJobOptions ¶ added in v0.3.0
type StoredJobOptions struct {
Queue string
Delay time.Duration
Timeout time.Duration
Retry int
Backoff time.Duration
UniqueFor time.Duration
}
StoredJobOptions is the stable delivery-policy shape persisted inside workflow records. Field names intentionally retain their version-one JSON casing. @group Queue
type ThroughputWindow ¶
ThroughputWindow captures processed vs failed counts in a fixed window. @group Observability
type WithoutOverlapping ¶
type WithoutOverlapping struct {
Key func(ctx context.Context, message Message) string
TTL time.Duration
Locker Locker
}
WithoutOverlapping serializes executions that resolve to the same key. @group Queue
type WorkerpoolConfig ¶
WorkerpoolConfig configures the in-memory workerpool q. @group Config
type WorkflowOutcomeStore ¶ added in v0.3.0
type WorkflowOutcomeStore interface {
WorkflowStore
// FailChainNode commits failure only while nodeID is the current unsettled node.
// owned remains true on replay while that node's failure owns the chain.
FailChainNode(ctx context.Context, chainID, nodeID string, cause error) (state ChainState, owned bool, err error)
// SettleBatchJob returns the first committed outcome for one batch member.
// owned remains true on same-outcome replay and false when the opposite outcome won.
// Ownership covers the outcome category; BatchState does not retain a per-member cause.
SettleBatchJob(ctx context.Context, batchID, jobID string, outcome BatchJobOutcome, cause error) (state BatchState, owned bool, err error)
}
WorkflowOutcomeStore strengthens WorkflowStore with first-writer ownership when duplicate physical deliveries disagree about a logical job outcome. Built-in stores implement this additive capability; established custom WorkflowStore implementations remain source-compatible. @group Queue
type WorkflowStore ¶
type WorkflowStore interface {
// CreateChain persists a newly accepted chain. ChainID and every NodeID must
// be non-empty, Nodes must contain at least one entry, and NodeIDs must be unique.
CreateChain(ctx context.Context, rec ChainRecord) error
// AdvanceChain atomically claims completedNode and returns the current successor.
// Repeating the same (chainID, completedNode) claim must not advance again.
// When done is true, GetChain must immediately expose Completed or Failed state.
AdvanceChain(ctx context.Context, chainID string, completedNode string) (next *ChainNode, done bool, err error)
// FailChain commits terminal failure without replacing completed state.
FailChain(ctx context.Context, chainID string, cause error) error
// GetChain returns current chain state.
GetChain(ctx context.Context, chainID string) (ChainState, error)
// CreateBatch persists a newly accepted batch. BatchID and every JobID must
// be non-empty, Jobs must contain at least one entry, and JobIDs must be unique.
CreateBatch(ctx context.Context, rec BatchRecord) error
// MarkBatchJobStarted records that one batch member began execution.
MarkBatchJobStarted(ctx context.Context, batchID, jobID string) error
// MarkBatchJobSucceeded commits the first outcome for (batchID, jobID).
// Duplicate outcomes must return current state without changing counters.
MarkBatchJobSucceeded(ctx context.Context, batchID, jobID string) (BatchState, bool, error)
// MarkBatchJobFailed commits the first outcome for (batchID, jobID).
// Duplicate outcomes must return current state without changing counters.
MarkBatchJobFailed(ctx context.Context, batchID, jobID string, cause error) (BatchState, bool, error)
// CancelBatch commits aggregate batch cancellation.
CancelBatch(ctx context.Context, batchID string) error
// GetBatch returns current batch state.
GetBatch(ctx context.Context, batchID string) (BatchState, error)
// MarkCallbackInvoked atomically claims one callback idempotency key.
MarkCallbackInvoked(ctx context.Context, key string) (bool, error)
// Prune removes terminal workflow state older than before.
Prune(ctx context.Context, before time.Time) error
}
WorkflowStore persists chain, batch, and callback state for orchestration. Implement WorkflowOutcomeStore as well when a custom store must arbitrate contradictory physical deliveries atomically; built-in stores provide both. @group Queue
func NewMemoryStore ¶ added in v0.3.0
func NewMemoryStore() WorkflowStore
NewMemoryStore creates an in-memory workflow state store. It copies chain nodes and payload bytes on creation and return so callers retain independent ownership. @group Constructors
func NewSQLStore ¶ added in v0.3.0
func NewSQLStore(config SQLStoreConfig) (WorkflowStore, error)
NewSQLStore creates a SQL-backed workflow state store. @group Constructors
func NewSQLStoreWithManagedSchema ¶ added in v0.3.0
func NewSQLStoreWithManagedSchema(config SQLStoreConfig) (WorkflowStore, error)
NewSQLStoreWithManagedSchema creates a SQL-backed workflow state store without executing schema DDL. The supplied database must already contain the dialect-correct workflow tables, including transition receipts. @group Constructors
Source Files
¶
- admin.go
- continuation.go
- database_config.go
- db_test_helpers.go
- defaults.go
- dispatch_acceptance.go
- driver.go
- driver_runtime.go
- fake_continuation.go
- fake_queue.go
- fake_workflow.go
- history_timeline.go
- job.go
- job_identity.go
- logger.go
- logical_job.go
- observability.go
- observability_job_type.go
- queue.go
- queue_local.go
- queue_null.go
- readiness.go
- runtime.go
- runtime_hook.go
- workflow_adapters.go
- workflow_middleware.go
- workflow_models.go
- workflow_store.go
Directories
¶
| Path | Synopsis |
|---|---|
|
driver
|
|
|
mysqlqueue
module
|
|
|
natsqueue
module
|
|
|
postgresqueue
module
|
|
|
rabbitmqqueue
module
|
|
|
redisqueue
module
|
|
|
sqlitequeue
module
|
|
|
sqlqueuecore
module
|
|
|
sqsqueue
module
|
|
|
temporalqueue
module
|
|
|
integration
module
|
|
|
internal
|
|
|
jobidentity
Package jobidentity centralizes logical payload normalization and telemetry correlation shared by queue and workflow layers.
|
Package jobidentity centralizes logical payload normalization and telemetry correlation shared by queue and workflow layers. |
|
observation
Package observation provides internal fan-out plumbing without depending on the queue package's public event model.
|
Package observation provides internal fan-out plumbing without depending on the queue package's public event model. |
|
readmecheck
Package readmecheck contains CI-only compile checks for curated manual README snippets.
|
Package readmecheck contains CI-only compile checks for curated manual README snippets. |
|
runtimehook
Package runtimehook provides a tiny internal hook registry used to avoid import cycles between the public queue package and internal bridge/test helpers introduced during API flattening.
|
Package runtimehook provides a tiny internal hook registry used to avoid import cycles between the public queue package and internal bridge/test helpers introduced during API flattening. |
|
uniqueness
Package uniqueness provides shared identity-claim primitives for queue drivers.
|
Package uniqueness provides shared identity-claim primitives for queue drivers. |
|
workflow
Package workflow owns the private workflow protocol and orchestration boundary.
|
Package workflow owns the private workflow protocol and orchestration boundary. |
|
Package queueconfig contains shared configuration structs used by optional driver modules.
|
Package queueconfig contains shared configuration structs used by optional driver modules. |
|
Package queuecore contains shared helper logic used by optional driver modules.
|
Package queuecore contains shared helper logic used by optional driver modules. |