Documentation
¶
Overview ¶
Package job defines mutable execution envelopes encoded with encoding/json. Local task functions and settlement callbacks are not serialized. Admission borrows payload bytes, while encoding and decoding allocate wire values. Validation bounds retry count and metadata; it is not authentication or a general payload-size limit.
Index ¶
- Constants
- Variables
- func Bool(val bool) *bool
- func Encode(m *Message) []byte
- func Float64(val float64) *float64
- func Int64(val int64) *int64
- func Time(v time.Duration) *time.Duration
- type AllowOption
- type Message
- func (m *Message) Ack() error
- func (m *Message) AcknowledgementRequired() bool
- func (m *Message) Bytes() []byte
- func (m *Message) CorrelationMetadata() map[string]string
- func (m *Message) Nack() error
- func (m *Message) NackFailure(err error) error
- func (m *Message) Payload() []byte
- func (m *Message) SetAcknowledgement(ack func() error, nack func() error)
- func (m *Message) SetFailureAcknowledgement(ack func() error, nack func(error) error)
- func (m *Message) TraceContextMetadata() map[string]string
- func (m *Message) Validate() error
- type Metadata
- type Options
- type TaskFunc
Constants ¶
const ( // MaxMetadataValueBytes bounds every user-supplied metadata identity. MaxMetadataValueBytes = 256 // MaxMetadataTags bounds user-supplied metadata dimensions. MaxMetadataTags = 32 // MaxCorrelationFields bounds the transport-neutral correlation carrier. MaxCorrelationFields = 3 // MaxCorrelationFieldBytes matches correlation codec field-name bounds. MaxCorrelationFieldBytes = 64 // MaxCorrelationValueBytes matches the largest supported correlation ID. MaxCorrelationValueBytes = 1024 // MaxTraceContextFields bounds caller-owned telemetry propagation carriers. MaxTraceContextFields = 16 // MaxTraceContextFieldBytes bounds telemetry propagation field names. MaxTraceContextFieldBytes = 64 // MaxTraceContextValueBytes bounds one telemetry propagation field value. MaxTraceContextValueBytes = 8192 // MaxTraceContextBytes bounds the complete telemetry propagation carrier. MaxTraceContextBytes = 8192 )
const DefaultMaxMessageBytes = 1024 * 1024
DefaultMaxMessageBytes bounds encoded messages to one mebibyte.
const MaxRetryCount int64 = 100
MaxRetryCount bounds additional handler retries per delivery; the first attempt and broker redelivery are separate.
Variables ¶
var ( // ErrInvalidMessageLimit reports a non-positive decode limit. ErrInvalidMessageLimit = errors.New("message byte limit must be positive") // ErrMessageTooLarge reports an encoded message above its decode limit. ErrMessageTooLarge = errors.New("message exceeds byte limit") // ErrInvalidMessage reports unsafe or inconsistent execution metadata. ErrInvalidMessage = errors.New("invalid message execution metadata") )
Functions ¶
func Bool ¶
Bool is a helper function that creates a pointer to a bool value. Useful for setting AllowOption fields that require *bool.
Example:
opts := AllowOption{Jitter: job.Bool(true)}
func Encode ¶
Encode returns a newly allocated JSON envelope, without validation or a size limit, and panics on marshal failure. A nil message encodes as JSON null.
func Float64 ¶
Float64 is a helper function that creates a pointer to a float64 value. Useful for setting AllowOption fields that require *float64.
Example:
opts := AllowOption{RetryFactor: job.Float64(1.5)}
func Int64 ¶
Int64 is a helper function that creates a pointer to an int64 value. Useful for setting AllowOption fields that require *int64.
Example:
opts := AllowOption{RetryCount: job.Int64(3)}
Types ¶
type AllowOption ¶
type AllowOption struct {
// RetryCount is additional attempts; nil selects zero.
RetryCount *int64 // Maximum retry attempts (nil uses default: 0)
// RetryDelay is fixed delay; nil/zero selects exponential backoff.
RetryDelay *time.Duration // Fixed delay between retries (nil uses exponential backoff)
// RetryFactor is backoff multiplier; nil selects two.
RetryFactor *float64 // Backoff multiplier (nil uses default: 2)
// RetryMin is initial backoff duration; nil selects 100ms.
RetryMin *time.Duration // Minimum backoff delay (nil uses default: 100ms)
// RetryMax is backoff cap; nil selects 10s.
RetryMax *time.Duration // Maximum backoff delay (nil uses default: 10s)
// Jitter enables randomized backoff; nil selects false.
Jitter *bool // Enable backoff jitter (nil uses default: false)
// Timeout is the total cooperative execution budget; nil selects 60 minutes.
Timeout *time.Duration // Job execution timeout (nil uses default: 60 minutes)
// Metadata is cloned from the first option; nil means no operational identity.
Metadata *Metadata // Optional bounded identity propagated to operational records
}
AllowOption provides optional configuration for individual job execution. All fields are pointers to distinguish between "not set" and "set to zero value". This allows partial configuration while keeping unspecified fields at their defaults.
Example usage:
opts := AllowOption{
RetryCount: job.Int64(3), // Retry failed jobs up to 3 times
Timeout: job.Time(5 * time.Minute), // 5 minute timeout
}
q.QueueTask(myTask, opts)
type Message ¶
type Message struct {
// Task is an in-process callback omitted from the wire envelope.
Task TaskFunc `json:"-" msgpack:"-"`
// Timeout is the positive total handler/retry budget; constructors default
// to 60 minutes. Timeout signals cancellation, not forced completion.
Timeout time.Duration `json:"timeout" msgpack:"timeout"`
// Body is borrowed application payload, base64-encoded in JSON.
Body []byte `json:"body" msgpack:"body"`
// RetryCount is remaining additional handler attempts, from zero to 100.
// The scheduler decrements it; broker redelivery counts are separate.
RetryCount int64 `json:"retry_count" msgpack:"retry_count"`
// RetryDelay is a nonnegative fixed retry delay; default zero selects backoff.
RetryDelay time.Duration `json:"retry_delay" msgpack:"retry_delay"`
// RetryFactor is the multiplying factor for each increment step.
//
// Defaults to 2.
RetryFactor float64 `json:"retry_factor" msgpack:"retry_factor"`
// RetryMin is the initial backoff duration when RetryDelay is zero.
//
// Defaults to 100 milliseconds.
RetryMin time.Duration `json:"retry_min" msgpack:"retry_min"`
// RetryMax caps backoff durations when RetryDelay is zero.
//
// Defaults to 10 seconds.
RetryMax time.Duration `json:"retry_max" msgpack:"retry_max"`
// Jitter eases contention by randomizing backoff steps
Jitter bool `json:"jitter" msgpack:"jitter"`
// Metadata is optional bounded identity retained for operational records.
Metadata *Metadata `json:"metadata,omitempty" msgpack:"metadata,omitempty"`
// contains filtered or unexported fields
}
Message is a mutable execution envelope. Do not modify it concurrently with encoding or execution: Queue consumes RetryCount during retries, Payload aliases Body, and settlement setters do not synchronize or enforce callback idempotency.
func Decode ¶
Decode decodes a JSON envelope with DefaultMaxMessageBytes and panics on error. Use DecodeE for an error-returning boundary.
func DecodeE ¶
DecodeE rejects a nonpositive byte limit or oversized input before JSON unmarshaling, then validates execution metadata. Unknown fields and duplicate keys follow encoding/json behavior; no package-specific nesting limit is added. Decoded payload bytes are owned by the returned message.
func NewMessage ¶
func NewMessage(m core.QueuedMessage, opts ...AllowOption) Message
NewMessage uses only the first AllowOption and borrows m.Bytes() as Body without another copy. Metadata maps and time are cloned by NewOptions. It does not validate options; it uses m.Bytes() verbatim and m must be non-nil.
func NewTask ¶
func NewTask(task TaskFunc, opts ...AllowOption) Message
NewTask creates a local, unserialized callback with defaults and only the first AllowOption. It does not validate options or start work.
func (*Message) AcknowledgementRequired ¶
AcknowledgementRequired reports whether backend settlement is attached.
func (*Message) Bytes ¶
Bytes returns a newly allocated JSON envelope and panics on marshal failure. It does not call Validate or apply a byte limit. Task and callbacks are omitted.
func (*Message) CorrelationMetadata ¶
CorrelationMetadata returns a copy of the transport-neutral carrier attached by a correlation-aware producer.
func (*Message) NackFailure ¶
NackFailure rejects unsuccessful processing with its classified cause.
func (*Message) Payload ¶
Payload returns Body without copying. The caller must coordinate any mutation with the owner of the message and its backing array.
func (*Message) SetAcknowledgement ¶
SetAcknowledgement attaches backend delivery settlement callbacks.
func (*Message) SetFailureAcknowledgement ¶
SetFailureAcknowledgement attaches settlement callbacks to a delivery whose backend needs the handler failure to choose retry or terminal behavior.
func (*Message) TraceContextMetadata ¶
TraceContextMetadata returns a copy of the transport-neutral telemetry carrier attached by a trace-aware producer.
func (*Message) Validate ¶
Validate checks positive Timeout, RetryCount in [0, MaxRetryCount], nonnegative RetryDelay and bounded metadata. Backoff factor/min/max are checked only when retries are enabled without a fixed delay. Body size and the maximum timeout are not checked. The receiver must be non-nil.
type Metadata ¶
type Metadata struct {
// OriginalID is optional application identity, distinct from backend source identity.
OriginalID string `json:"original_id,omitempty" msgpack:"original_id,omitempty"`
// PayloadSchemaVersion identifies an application schema this package does not validate.
PayloadSchemaVersion string `json:"payload_schema_version,omitempty" msgpack:"payload_schema_version,omitempty"`
// ContentType is optional claimed media type, not verified content.
ContentType string `json:"content_type,omitempty" msgpack:"content_type,omitempty"`
// EnqueuedAt is an optional nonzero time; nil means unknown.
EnqueuedAt *time.Time `json:"enqueued_at,omitempty" msgpack:"enqueued_at,omitempty"`
// RetryPolicy is optional policy identity, not executable retry configuration.
RetryPolicy string `json:"retry_policy,omitempty" msgpack:"retry_policy,omitempty"`
// HandlerType is an optional handler label, not serialized code.
HandlerType string `json:"handler_type,omitempty" msgpack:"handler_type,omitempty"`
// JobType is optional application job identity.
JobType string `json:"job_type,omitempty" msgpack:"job_type,omitempty"`
// Tags contains mutable bounded dimensions; values are not automatically redacted.
Tags map[string]string `json:"tags,omitempty" msgpack:"tags,omitempty"`
// TraceID is claimed trace identity, not authenticated evidence.
TraceID string `json:"trace_id,omitempty" msgpack:"trace_id,omitempty"`
// TenantID is claimed tenancy metadata, not access enforcement.
TenantID string `json:"tenant_id,omitempty" msgpack:"tenant_id,omitempty"`
// ProducerVersion identifies the producing application when known.
ProducerVersion string `json:"producer_version,omitempty" msgpack:"producer_version,omitempty"`
// Correlation is a mutable bounded transport carrier, not authenticated identity.
Correlation map[string]string `json:"correlation,omitempty" msgpack:"correlation,omitempty"`
// TraceContext is a mutable telemetry carrier bounded by count and total bytes.
TraceContext map[string]string `json:"trace_context,omitempty" msgpack:"trace_context,omitempty"`
}
Metadata carries optional, backend-neutral job identity into failure and dead-letter records. Empty fields remain unknown and must not be fabricated.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options configures retry behavior and timeouts for individual jobs. These settings control how failed tasks are retried and when they time out.
func NewOptions ¶
func NewOptions(opts ...AllowOption) Options
NewOptions overlays defaults with only the first AllowOption; later values are ignored. Pointer fields are read immediately, and metadata maps/time are cloned. Validation is deferred to Message.Validate or queue admission.