queue

package
v0.0.0-...-e6d59a1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RetryPolicyDefault        = 25
	RetryPolicyEmphemeral     = 0
	RetryPolicyDirectToMorgue = -1
)

Functions

func RandomJid

func RandomJid() string

Types

type Dlqer

type Dlqer interface {
	RequeueDeadJob(job *Job) error
}

type Failure

type Failure struct {
	RetryCount     int      `json:"retry_count"`
	RetryRemaining int      `json:"remaining"`
	FailedAt       string   `json:"failed_at"`
	NextAt         string   `json:"next_at,omitempty"`
	ErrorMessage   string   `json:"message,omitempty"`
	ErrorType      string   `json:"errtype,omitempty"`
	Backtrace      []string `json:"backtrace,omitempty"`
}

type Helper

type Helper interface {
	Jid() string
	JobType() string

	// Custom provides access to the job custom hash.
	// Returns the value and `ok=true` if the key was found.
	// If not, returns `nil` and `ok=false`.
	//
	// No type checking is performed, please use with caution.
	Custom(key string) (value interface{}, ok bool)

	// Faktory Enterprise:
	// the BID of the Batch associated with this job
	Bid() string

	// Faktory Enterprise:
	// the BID of the Batch associated with this callback (complete or success) job
	CallbackBid() string

	// Faktory Enterprise:
	// open the batch associated with this job so we can add more jobs to it.
	//
	//   func myJob(ctx context.Context, args ...interface{}) error {
	//     helper := worker.HelperFor(ctx)
	//     helper.Batch(func(b *faktory.Batch) error {
	//       return b.Push(faktory.NewJob("sometype", 1, 2, 3))
	//     })
	Batch(func(*faktory.Batch) error) error

	// allows direct access to the Faktory server from the job
	With(func(*faktory.Client) error) error

	// Faktory Enterprise:
	// this method integrates with Faktory Enterprise's Job Tracking feature.
	// `reserveUntil` is optional, only needed for long jobs which have more dynamic
	// lifetimes.
	//
	//     helper.TrackProgress(10, "Updating code...", nil)
	//     helper.TrackProgress(20, "Cleaning caches...", &time.Now().Add(1 * time.Hour)))
	//
	TrackProgress(percent int, desc string, reserveUntil *time.Time) error
}

type Job

type Job struct {
	// required
	Jid   string        `json:"jid"`
	Queue string        `json:"queue"`
	Type  string        `json:"jobtype"`
	Args  []interface{} `json:"args"`

	// optional
	CreatedAt  string                 `json:"created_at,omitempty"`
	EnqueuedAt string                 `json:"enqueued_at,omitempty"`
	At         string                 `json:"at,omitempty"`
	ReserveFor int                    `json:"reserve_for,omitempty"`
	Retry      *int                   `json:"retry"`
	Backtrace  int                    `json:"backtrace,omitempty"`
	Failure    *Failure               `json:"failure,omitempty"`
	Custom     map[string]interface{} `json:"custom,omitempty"`
}

func NewJob

func NewJob(jobtype string, args ...interface{}) *Job

Clients should use this constructor to build a Job, not allocate a bare struct directly.

func (*Job) GetCustom

func (j *Job) GetCustom(name string) (interface{}, bool)

func (*Job) JsonBytes

func (j *Job) JsonBytes() ([]byte, error)

func (*Job) SetCustom

func (j *Job) SetCustom(name string, value interface{}) *Job

Set custom metadata for this job. Faktory reserves all element names starting with "_" for internal use, e.g. SetCustom("_txid", "12345")

func (*Job) SetExpiresAt

func (j *Job) SetExpiresAt(expiresAt time.Time) *Job

Configure the TTL for this job. After this point in time, the job will be discarded rather than executed.

func (*Job) SetExpiresIn

func (j *Job) SetExpiresIn(expiresIn time.Duration) *Job

func (*Job) SetUniqueFor

func (j *Job) SetUniqueFor(secs uint) *Job

Configure this job to be unique for +secs+ seconds or until the job has been successfully processed.

func (*Job) SetUniqueness

func (j *Job) SetUniqueness(until UniqueUntil) *Job

Configure the uniqueness deadline for this job, legal values are:

  • "success" - the job will be considered unique until it has successfully processed or the +unique_for+ TTL has passed, this is the default value.
  • "start" - the job will be considered unique until it starts processing. Retries may lead to multiple copies of the job running.

type JobProcessor

type JobProcessor func(helper Helper, args ...interface{}) error

type UniqueUntil

type UniqueUntil string
const (
	UntilSuccess UniqueUntil = "success" // default
	UntilStart   UniqueUntil = "start"
)

Jump to

Keyboard shortcuts

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