tasks

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package tasks provides utilities for Google Cloud Tasks operations including task creation, queue management, and retry policies.

Index

Constants

This section is empty.

Variables

View Source
var StandardQueues = struct {
	Default   string
	Critical  string
	Bulk      string
	Scheduled string
}{
	Default:   "default",
	Critical:  "critical",
	Bulk:      "bulk",
	Scheduled: "scheduled",
}

StandardQueues provides standard queue names

Functions

This section is empty.

Types

type CloudTaskQueue

type CloudTaskQueue struct {
	// contains filtered or unexported fields
}

CloudTaskQueue implements TaskQueue using Google Cloud Tasks

func NewCloudTaskQueue

func NewCloudTaskQueue(ctx context.Context) (*CloudTaskQueue, error)

NewCloudTaskQueue creates a new cloud-based task queue

func (*CloudTaskQueue) CreateHTTPTask

func (q *CloudTaskQueue) CreateHTTPTask(ctx context.Context, queueName string, url string, payload interface{}) error

CreateHTTPTask creates an HTTP task in the cloud queue

func (*CloudTaskQueue) CreateTask

func (q *CloudTaskQueue) CreateTask(ctx context.Context, task *Task) error

CreateTask creates a new task in the cloud queue

func (*CloudTaskQueue) DeleteTask

func (q *CloudTaskQueue) DeleteTask(ctx context.Context, queueName string, taskName string) error

DeleteTask deletes a task from the cloud queue

func (*CloudTaskQueue) GetQueueStats

func (q *CloudTaskQueue) GetQueueStats(ctx context.Context, queueName string) (*QueueStats, error)

GetQueueStats returns statistics for a cloud queue

func (*CloudTaskQueue) PurgeQueue

func (q *CloudTaskQueue) PurgeQueue(ctx context.Context, queueName string) error

PurgeQueue purges all tasks from a cloud queue

type LocalTaskQueue

type LocalTaskQueue struct {
	// contains filtered or unexported fields
}

LocalTaskQueue implements TaskQueue using in-memory storage for development

func NewLocalTaskQueue

func NewLocalTaskQueue() *LocalTaskQueue

NewLocalTaskQueue creates a new local in-memory task queue

func (*LocalTaskQueue) CreateHTTPTask

func (q *LocalTaskQueue) CreateHTTPTask(ctx context.Context, queueName string, url string, payload interface{}) error

CreateHTTPTask creates an HTTP task in the local queue

func (*LocalTaskQueue) CreateTask

func (q *LocalTaskQueue) CreateTask(ctx context.Context, task *Task) error

CreateTask creates a new task in the local queue

func (*LocalTaskQueue) DeleteTask

func (q *LocalTaskQueue) DeleteTask(ctx context.Context, queueName string, taskName string) error

DeleteTask deletes a task from the local queue

func (*LocalTaskQueue) GetQueueStats

func (q *LocalTaskQueue) GetQueueStats(ctx context.Context, queueName string) (*QueueStats, error)

GetQueueStats returns statistics for a local queue

func (*LocalTaskQueue) PurgeQueue

func (q *LocalTaskQueue) PurgeQueue(ctx context.Context, queueName string) error

PurgeQueue purges all tasks from a local queue

func (*LocalTaskQueue) Stop

func (q *LocalTaskQueue) Stop()

Stop stops the local task queue processor

type QueueStats

type QueueStats struct {
	TasksCount      int64
	OldestTaskAge   time.Duration
	ExecutedLastMin int64
	ConcurrentTasks int64
}

QueueStats contains statistics about a queue

type RetryConfig

type RetryConfig struct {
	MaxAttempts      int           // Maximum number of attempts
	MaxRetryDuration time.Duration // Maximum time to retry
	MinBackoff       time.Duration // Minimum backoff duration
	MaxBackoff       time.Duration // Maximum backoff duration
	MaxDoublings     int           // Maximum number of backoff doublings
}

RetryConfig defines retry behavior for tasks

func DefaultRetryConfig

func DefaultRetryConfig() *RetryConfig

DefaultRetryConfig returns a default retry configuration

type Task

type Task struct {
	Name        string            // Task name (optional, will be generated if empty)
	Queue       string            // Queue name
	URL         string            // Target URL for HTTP tasks
	Method      string            // HTTP method (GET, POST, etc.)
	Headers     map[string]string // HTTP headers
	Payload     interface{}       // Task payload (will be JSON encoded)
	ScheduleAt  time.Time         // When to execute the task
	RetryConfig *RetryConfig      // Retry configuration
}

Task represents a task to be executed

type TaskQueue

type TaskQueue interface {
	// CreateTask creates a new task in the queue
	CreateTask(ctx context.Context, task *Task) error

	// CreateHTTPTask creates an HTTP task
	CreateHTTPTask(ctx context.Context, queueName string, url string, payload interface{}) error

	// DeleteTask deletes a task from the queue
	DeleteTask(ctx context.Context, queueName string, taskName string) error

	// PurgeQueue purges all tasks from a queue
	PurgeQueue(ctx context.Context, queueName string) error

	// GetQueueStats returns statistics for a queue
	GetQueueStats(ctx context.Context, queueName string) (*QueueStats, error)
}

TaskQueue provides an interface for task queue operations

func NewTaskQueue

func NewTaskQueue(ctx context.Context) (TaskQueue, error)

NewTaskQueue creates a new task queue based on the environment

Jump to

Keyboard shortcuts

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