queue

package
v0.0.0-...-358e9ac Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Queues = map[string]int{
	Critical.String(): 6,
	Default.String():  3,
	Low.String():      1,
}

Functions

This section is empty.

Types

type BaseTask

type BaseTask struct {
	LastErr   error           `json:"last_error,omitempty"`
	ProcessIn []time.Duration `json:"process_in,omitempty"`
	Queue     Queue           `json:"queue,omitempty"`
	TaskType  TaskType        `json:"task_type,omitempty"`
}

func NewTask

func NewTask(t TaskType) BaseTask

NewTask creates a new Task running on the Default Queue

func NewTaskOnQueue

func NewTaskOnQueue(q Queue, t TaskType) BaseTask

NewTaskOnQueue creates a Task to be run on the provided Queue

func (*BaseTask) LastError

func (b *BaseTask) LastError() error

func (*BaseTask) OnQueue

func (b *BaseTask) OnQueue() Queue

func (*BaseTask) RunIn

func (b *BaseTask) RunIn() []time.Duration

func (*BaseTask) Type

func (b *BaseTask) Type() TaskType

type Processor

type Processor interface {
	Run(workers ...Worker) error
}

Processor starts and manages all the Worker handling a Task

Run starts the task processing and blocks until an os signal to exit the program is received. Once it receives a signal, it gracefully shuts down all active workers and other goroutines to process the tasks.

type Queue

type Queue string

Queue represents the queue which a Task runs on.

const (
	Critical Queue = "critical"
	Default  Queue = "default"
	Low      Queue = "low"
)

func (Queue) String

func (p Queue) String() string

type Queuer

type Queuer interface {
	Close() error
	Enqueue(ctx context.Context, task Task) error
}

Queuer provides methods for managing the queue

Close closes the underlying connection for the given driver Enqueue adds the Task to the Queue

type Task

type Task interface {
	LastError() error
	OnQueue() Queue
	RunIn() []time.Duration
	Type() TaskType
}

Task queues a job to be executed.

LastError stores the last error encountered whn running the Task

OnQueue indicates the Queue the Task should be executed on.

RunIn indicates when to run the Task.

Type is an identifier for the Task.

type TaskType

type TaskType string
const (
	HelloTask TaskType = "hello"
)

func (TaskType) String

func (t TaskType) String() string

type Worker

type Worker interface {
	Key() TaskType
	GenericHandler(ctx context.Context, t Task) error
	RedisHandler(ctx context.Context, t *asynq.Task) error
}

Worker processes a Task based on its configuration.

Key is a unique identifier for the Task being executed Handler processes the given Task

Jump to

Keyboard shortcuts

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