task

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager interface {
	common.Service
	common.Daemon
	Add(tasks ...*Task) error
	Remove(tasks ...*Task)
	Trigger(id string, params any) error
	Cancel(id string) error
	Stats(id string) *Stats
}

func New

func New(opts ...Option) Manager

type Option

type Option func(*manager)

func MaxConcurrency

func MaxConcurrency(size int) Option

func WithLogger

func WithLogger(logger log.Logger) Option

type Stats added in v0.7.0

type Stats struct {
	executor.Stats
	Requeues uint          `json:"requeues"` // times the latest execution went back to the queue
	Cooldown time.Duration `json:"cooldown"` // what is left of the current RequeueCooldown
}

Stats is what the task's executor reports, plus what the manager adds on top of it.

type Task

type Task struct {
	Job      job.Job         `json:"-"`
	Ctx      context.Context `json:"-"`
	Params   any             `json:"params"`
	Schedule string          `json:"schedule"`
	// Manual keeps the task registered without running it on its own: only Trigger does.
	Manual        bool          `json:"manual,omitempty"`
	Priority      int           `json:"priority"`
	Exclusive     bool          `json:"exclusive"`
	Timeout       time.Duration `json:"timeout,omitempty"`
	RetryAttempts int           `json:"retry_attempts,omitempty"`
	RetryDelay    time.Duration `json:"retry_delay,omitempty"`
	// RequeueAttempts is how many times a failed execution, its retries used
	// up, goes back to the queue. Unlike a retry it gives up its worker while
	// it waits, and it counts on top: a task runs up to
	// (RetryAttempts+1) * (RequeueAttempts+1) times.
	RequeueAttempts int `json:"requeue_attempts,omitempty"`
	// RequeueCooldown is how long a failed execution waits before going back to
	// the queue.
	RequeueCooldown time.Duration `json:"requeue_cooldown,omitempty"`
	// contains filtered or unexported fields
}

func (*Task) GetPriority

func (t *Task) GetPriority() int

func (*Task) ID added in v0.7.0

func (t *Task) ID() string

ID is the task's identity, its job's ID; look tasks up by ID only.

func (*Task) IsRequeueing added in v0.7.0

func (t *Task) IsRequeueing() bool

IsRequeueing reports whether the task failed and is waiting to run again, cooling down or back in the queue. Its job stays failed meanwhile: that run did fail.

func (*Task) IsValid

func (t *Task) IsValid() bool

func (*Task) Key

func (t *Task) Key() string

Key only satisfies common.Unique for the priority queue; it is the ID.

func (*Task) SetPriority

func (t *Task) SetPriority(priority int)

func (*Task) String

func (t *Task) String() string

Jump to

Keyboard shortcuts

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