Documentation
¶
Index ¶
- Constants
- type Client
- type Config
- type Dispatcher
- type Hook
- type Task
- type TaskOption
- func WithDependencies(dependencies []string) TaskOption
- func WithExecuteAt(executeAt time.Time) TaskOption
- func WithPriority(priority int) TaskOption
- func WithRetentionTime(retention time.Duration) TaskOption
- func WithRetry(maxRetries int, initialBackoff, maxBackoff time.Duration, ...) TaskOption
- func WithTimeout(timeout time.Duration) TaskOption
- type TaskStatus
Constants ¶
const ( PriorityLow = 1 PriorityNormal = 2 PriorityHigh = 3 )
Priority levels for tasks
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Task management EnqueueTask(ctx context.Context, queueName string, payload []byte, opts ...TaskOption) (*Task, error) CancelTask(ctx context.Context, taskID string) error GetTask(ctx context.Context, taskID string) (*Task, error) ListTasks(ctx context.Context, queueName string) ([]*Task, error) // Queue management PauseQueue(ctx context.Context, queueName string) error ResumeQueue(ctx context.Context, queueName string) error // Periodic tasks SchedulePeriodicTask(ctx context.Context, queueName string, payload []byte, interval time.Duration, opts ...TaskOption) (*Task, error) // Cleanup CleanupTasks(ctx context.Context) error // GetConfig returns the current configuration GetConfig() *Config }
Client interface defines methods for interacting with the task queue
type Config ¶
type Config struct { DB *gorm.DB NumWorkers int RetentionPeriod time.Duration PreHooks []Hook PostHooks []Hook ServerID string // Unique ID for this server instance LockTTL time.Duration // How long a task lock is valid DefaultTimeout time.Duration DefaultMaxRetries int DefaultInitialBackoff time.Duration DefaultMaxBackoff time.Duration DefaultBackoffFactor float64 // contains filtered or unexported fields }
Config represents the configuration for the task queue
type Dispatcher ¶
type Dispatcher interface { Start(ctx context.Context) error Stop(ctx context.Context) error AddWorker() error RemoveWorker() error }
Dispatcher interface defines methods for task dispatching and worker management
func NewDispatcher ¶
func NewDispatcher(config *Config) (Dispatcher, error)
NewDispatcher creates a new task dispatcher
type Task ¶
type Task struct { ID string `gorm:"primarykey"` QueueName string `gorm:"index"` Status TaskStatus `gorm:"index"` Priority int `gorm:"index"` Payload json.RawMessage `gorm:"type:jsonb"` Dependencies pq.StringArray `gorm:"type:text[]"` // Using pq.StringArray for proper PostgreSQL array handling ExecuteAt *time.Time `gorm:"index"` RetentionTime *time.Time CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` LockedBy string `gorm:"index"` // Server ID that locked this task LockedAt *time.Time // When the task was locked LockTimeout *time.Time // When the lock expires // Timeout settings Timeout time.Duration // Maximum execution time for the task // Retry settings RetryCount int `gorm:"default:0"` // Current retry attempt MaxRetries int `gorm:"default:3"` // Maximum number of retry attempts LastError string // Last error message NextRetryAt *time.Time `gorm:"index"` // When to retry next InitialBackoff time.Duration // Initial backoff duration MaxBackoff time.Duration // Maximum backoff duration BackoffFactor float64 // Multiplier for exponential backoff }
Task represents a background task
type TaskOption ¶
type TaskOption func(*Task)
TaskOption represents options for task creation
func WithDependencies ¶
func WithDependencies(dependencies []string) TaskOption
WithDependencies sets the dependencies for a task
func WithExecuteAt ¶
func WithExecuteAt(executeAt time.Time) TaskOption
WithExecuteAt sets the execution time for a task
func WithPriority ¶
func WithPriority(priority int) TaskOption
WithPriority sets the priority of a task
func WithRetentionTime ¶
func WithRetentionTime(retention time.Duration) TaskOption
WithRetentionTime sets the retention time for a task
func WithRetry ¶
func WithRetry(maxRetries int, initialBackoff, maxBackoff time.Duration, backoffFactor float64) TaskOption
WithRetry sets the retry configuration for a task
func WithTimeout ¶
func WithTimeout(timeout time.Duration) TaskOption
WithTimeout sets the maximum execution time for a task
type TaskStatus ¶
type TaskStatus string
TaskStatus represents the current state of a task
const ( TaskStatusPending TaskStatus = "pending" TaskStatusRunning TaskStatus = "running" TaskStatusCompleted TaskStatus = "completed" TaskStatusFailed TaskStatus = "failed" TaskStatusCanceled TaskStatus = "canceled" )