v1.1.3

API Reference

Last updated


This page lists the Queue methods and the exported types of github.com/pardnchiu/go-queue/core.

Queue


  1. func New(config *Config) *Queue
  2. func (q *Queue) Start(ctx context.Context) error
  3. func (q *Queue) Enqueue(ctx context.Context, presetName string, action func(ctx context.Context) error, options ...EnqueueOption) (string, error)
  4. func (q *Queue) Shutdown(ctx context.Context) error

MethodDescription
NewCreates a queue and merges defaults; config may be nil. The queue starts in the Created state
StartLaunches Workers workers. ctx is the parent of every task ctx; cancelling it does not stop workers, but later tasks receive an already-cancelled ctx
EnqueuePushes a task and returns its ID. ctx is only checked for cancellation before enqueueing and is not passed to the task; the task gets a timeout ctx derived from the Start ctx
ShutdownMoves to Closed, wakes every worker, and waits for the heap to drain. When ctx expires it cancels every task ctx and returns an error; repeated calls return nil

Config and PresetConfig


  1. type Config struct {
  2. Workers int
  3. Size int
  4. Timeout time.Duration
  5. Preset map[string]PresetConfig
  6. }
  7. type PresetConfig struct {
  8. Priority Priority
  9. Timeout time.Duration
  10. }

Fields and defaults: Configuration and Presets.

Priority


  1. type Priority int
  2. const (
  3. PriorityImmediate Priority = iota
  4. PriorityHigh
  5. PriorityRetry
  6. PriorityNormal
  7. PriorityLow
  8. )

Lower values run first. See Priority Levels and Timeout Derivation.
Other reference pages: Enqueue Options, Errors, Log Events, Removed API.
中文