job

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 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 routine that allocates a new bool value

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 routine that allocates a new float64 value

func Int64

func Int64(val int64) *int64

Int64 is a helper routine that allocates a new int64 value

func Time

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

Time is a helper routine that allocates a new time value

Types

type AllowOption

type AllowOption struct {
	RetryCount  *int64
	RetryDelay  *time.Duration
	RetryFactor *float64
	RetryMin    *time.Duration
	RetryMax    *time.Duration
	Jitter      *bool
	Timeout     *time.Duration
}

AllowOption is a function that sets some option on the Options

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 is a set of options for the queue

func NewOptions

func NewOptions(opts ...AllowOption) Options

NewOptions create new options

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