tasks

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueueActionPause         = "pause"
	QueueActionUnpause       = "unpause"
	QueueActionRetry         = "retry"
	QueueActionArchiveRetry  = "archive-retry"
	QueueActionRetryArchived = "retry-archived"
	QueueActionPurgeArchived = "purge-archived"
)

Variables

View Source
var (
	ErrNilHandler       = fmt.Errorf("tasks: handler is nil")
	ErrNilManager       = fmt.Errorf("tasks: manager is nil")
	ErrRedisURLRequired = fmt.Errorf("tasks: redis_url is required")
	ErrTaskTypeRequired = fmt.Errorf("tasks: task type is required")
)

Functions

func DecodeJSONPayload

func DecodeJSONPayload(task Task, dst any) error

DecodeJSONPayload unmarshals a generic JSON task payload into dst.

func NormalizeQueueAction

func NormalizeQueueAction(raw string) (string, bool)

func SupportedQueueActions

func SupportedQueueActions() []string

Types

type Config

type Config struct {
	RedisURL       string         // Used if Provider needs Redis (e.g. Asynq)
	Concurrency    int            // Number of concurrent workers
	Queues         map[string]int // Queue names and their priority weights
	StrictPriority bool           // If true, strict priority ordering is enforced
}

Config configures task enqueueing and worker runtime.

type EnqueuePolicy

type EnqueuePolicy struct {
	Queue     string
	MaxRetry  int
	Timeout   time.Duration
	ProcessIn time.Duration
	Retention time.Duration
}

EnqueuePolicy describes the supported explicit enqueue-policy subset. MaxRetry uses -1 to keep provider defaults; 0 disables retries.

func DefaultEnqueuePolicy

func DefaultEnqueuePolicy() EnqueuePolicy

type HandlerFunc

type HandlerFunc func(ctx context.Context, task Task) error

HandlerFunc is a function that processes a Task.

type Inspector

type Inspector interface {
	InspectRuntime() RuntimeSnapshot
	OperateQueue(queue, action string) (QueueActionResult, error)
}

Inspector defines an interface for queue introspection and operations.

type Manager

type Manager interface {
	// Worker methods
	HandleFunc(taskType string, handler HandlerFunc) error
	Run(ctx context.Context) error
	Close() error

	// Client methods
	EnqueueJSON(taskType string, payload any) (string, error)
	EnqueueJSONCtx(ctx context.Context, taskType string, payload any) (string, error)
	EnqueueJSONWithPolicy(taskType string, payload any, policy EnqueuePolicy) (string, error)
	EnqueueJSONCtxWithPolicy(ctx context.Context, taskType string, payload any, policy EnqueuePolicy) (string, error)
}

Manager is the unified interface for a Task Queue Provider.

type QueueActionResult

type QueueActionResult struct {
	Enabled     bool   `json:"enabled"`
	GeneratedAt string `json:"generated_at"`
	Queue       string `json:"queue"`
	Action      string `json:"action"`
	Applied     bool   `json:"applied"`
	Affected    int    `json:"affected,omitempty"`
	Message     string `json:"message,omitempty"`
}

QueueActionResult is the result of one operational queue action.

type RuntimeQueueSnapshot

type RuntimeQueueSnapshot struct {
	Name           string `json:"name"`
	Paused         bool   `json:"paused"`
	LatencyMS      int64  `json:"latency_ms"`
	Size           int    `json:"size"`
	Pending        int    `json:"pending"`
	Active         int    `json:"active"`
	Scheduled      int    `json:"scheduled"`
	Retry          int    `json:"retry"`
	Archived       int    `json:"archived"`
	Completed      int    `json:"completed"`
	Aggregating    int    `json:"aggregating"`
	ProcessedToday int    `json:"processed_today"`
	FailedToday    int    `json:"failed_today"`
	ProcessedAll   int    `json:"processed_all"`
	FailedAll      int    `json:"failed_all"`
}

RuntimeQueueSnapshot holds one queue aggregate.

type RuntimeScheduleSnapshot

type RuntimeScheduleSnapshot struct {
	ID            string `json:"id"`
	Spec          string `json:"spec"`
	TaskType      string `json:"task_type"`
	NextEnqueueAt string `json:"next_enqueue_at,omitempty"`
	PrevEnqueueAt string `json:"prev_enqueue_at,omitempty"`
}

RuntimeScheduleSnapshot holds one registered periodic task entry.

type RuntimeServerSnapshot

type RuntimeServerSnapshot struct {
	ID             string         `json:"id"`
	Host           string         `json:"host"`
	PID            int            `json:"pid"`
	Status         string         `json:"status"`
	StartedAt      string         `json:"started_at,omitempty"`
	Concurrency    int            `json:"concurrency"`
	StrictPriority bool           `json:"strict_priority"`
	Queues         map[string]int `json:"queues"`
	ActiveWorkers  int            `json:"active_workers"`
}

RuntimeServerSnapshot holds one server aggregate.

type RuntimeSnapshot

type RuntimeSnapshot struct {
	Enabled           bool                      `json:"enabled"`
	GeneratedAt       string                    `json:"generated_at"`
	Reason            string                    `json:"reason,omitempty"`
	Queues            []RuntimeQueueSnapshot    `json:"queues"`
	Schedules         []RuntimeScheduleSnapshot `json:"schedules"`
	Servers           []RuntimeServerSnapshot   `json:"servers"`
	Workers           []RuntimeWorkerSnapshot   `json:"workers"`
	TotalSchedules    int                       `json:"total_schedules"`
	TotalQueues       int                       `json:"total_queues"`
	TotalServers      int                       `json:"total_servers"`
	TotalWorkers      int                       `json:"total_workers"`
	TotalSize         int                       `json:"total_size"`
	TotalPending      int                       `json:"total_pending"`
	TotalActive       int                       `json:"total_active"`
	TotalScheduled    int                       `json:"total_scheduled"`
	TotalRetry        int                       `json:"total_retry"`
	TotalArchived     int                       `json:"total_archived"`
	TotalCompleted    int                       `json:"total_completed"`
	TotalAggregating  int                       `json:"total_aggregating"`
	TotalProcessed    int                       `json:"total_processed_today"`
	TotalFailed       int                       `json:"total_failed_today"`
	TotalProcessedAll int                       `json:"total_processed_all"`
	TotalFailedAll    int                       `json:"total_failed_all"`
}

RuntimeSnapshot describes queue/worker state discoverable from the provider runtime.

type RuntimeWorkerSnapshot

type RuntimeWorkerSnapshot struct {
	ServerID  string `json:"server_id"`
	Host      string `json:"host"`
	PID       int    `json:"pid"`
	Queue     string `json:"queue"`
	TaskID    string `json:"task_id"`
	TaskType  string `json:"task_type"`
	StartedAt string `json:"started_at,omitempty"`
	Deadline  string `json:"deadline,omitempty"`
}

RuntimeWorkerSnapshot describes one active worker task.

type Scheduler

type Scheduler interface {
	RegisterJSON(spec, taskType string, payload any, policy EnqueuePolicy) (string, error)
	Unregister(entryID string) error
	Start() error
	Close() error
}

Scheduler provides an interface for periodic background tasks.

type Task

type Task interface {
	Type() string
	Payload() []byte
}

Task represents a generic unit of work.

Directories

Path Synopsis
providers
asynq
Package tasks provides background job enqueueing and worker runtime backed by Asynq.
Package tasks provides background job enqueueing and worker runtime backed by Asynq.

Jump to

Keyboard shortcuts

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