job

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 4 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(val bool) *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

func Encode(m *Message) []byte

Encode takes a Message struct and marshals it into a byte slice using msgpack. If the marshalling process encounters an error, the function will panic. It returns the marshalled byte slice.

Parameters:

  • m: A pointer to the Message struct to be encoded.

Returns:

  • A byte slice containing the msgpack-encoded data.

func Float64

func Float64(val float64) *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

func Int64(val int64) *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)}

func Time

func Time(v time.Duration) *time.Duration

Time is a helper function that creates a pointer to a time.Duration value. Useful for setting AllowOption fields that require *time.Duration.

Example:

opts := AllowOption{
    Timeout:    job.Time(5 * time.Minute),
    RetryDelay: job.Time(2 * time.Second),
}

Types

type AllowOption

type AllowOption struct {
	RetryCount  *int64         // Maximum retry attempts (nil uses default: 0)
	RetryDelay  *time.Duration // Fixed delay between retries (nil uses exponential backoff)
	RetryFactor *float64       // Backoff multiplier (nil uses default: 2)
	RetryMin    *time.Duration // Minimum backoff delay (nil uses default: 100ms)
	RetryMax    *time.Duration // Maximum backoff delay (nil uses default: 10s)
	Jitter      *bool          // Enable backoff jitter (nil uses default: false)
	Timeout     *time.Duration // Job execution timeout (nil uses default: 60 minutes)
}

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 TaskFunc `json:"-" msgpack:"-"`

	// Timeout is the duration the task can be processed by Handler.
	// zero if not specified
	// default is 60 time.Minute
	Timeout time.Duration `json:"timeout" msgpack:"timeout"`

	// Payload is the payload data of the task.
	Body []byte `json:"body" msgpack:"body"`

	// RetryCount set count of retry
	// default is 0, no retry.
	RetryCount int64 `json:"retry_count" msgpack:"retry_count"`

	// RetryDelay set delay between retry
	// default is 100ms
	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"`

	// Minimum value of the counter.
	//
	// Defaults to 100 milliseconds.
	RetryMin time.Duration `json:"retry_min" msgpack:"retry_min"`

	// Maximum value of the counter.
	//
	// 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"`
}

Message describes a task and its metadata.

func Decode

func Decode(b []byte) *Message

Decode takes a byte slice and unmarshals it into a Message struct using msgpack. If the unmarshalling process encounters an error, the function will panic. It returns a pointer to the unmarshalled Message.

Parameters:

  • b: A byte slice containing the msgpack-encoded data.

Returns:

  • A pointer to the decoded Message struct.

func NewMessage

func NewMessage(m core.QueuedMessage, opts ...AllowOption) Message

NewMessage create new message

func NewTask

func NewTask(task TaskFunc, opts ...AllowOption) Message

func (*Message) Bytes

func (m *Message) Bytes() []byte

Bytes returns the byte slice of the Message struct. If the marshalling process encounters an error, the function will panic. It returns the marshalled byte slice.

Returns:

  • A byte slice containing the msgpack-encoded data.

func (*Message) Payload

func (m *Message) Payload() []byte

Payload returns the payload data of the Message. It returns the byte slice of the payload.

Returns:

  • A byte slice containing the payload data.

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 creates a job Options struct by merging defaults with provided AllowOption values. Only non-nil fields in AllowOption will override the defaults. This allows partial configuration where unspecified options retain their default values.

Example:

// Only override retry count and timeout, keep other defaults
opts := job.NewOptions(job.AllowOption{
    RetryCount: job.Int64(5),
    Timeout:    job.Time(10 * time.Minute),
})

type TaskFunc

type TaskFunc func(context.Context) error

TaskFunc is the task function

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL