queue

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

Queue represents a task queue.

func NewQueue

func NewQueue(ctx context.Context, log *zap.Logger) *Queue

NewQueue creates a new Queue.

func (*Queue) AddTask

func (q *Queue) AddTask(exec func() (interface{}, error)) *TaskResult

AddTask adds a task to the queue and runs it.

func (*Queue) GetResult

func (q *Queue) GetResult(id string) (*TaskResult, error)

GetResult retrieves the result and status of a task by its ID.

type Task

type Task struct {
	ID             string
	Exec           func() (interface{}, error)
	Status         TaskStatus
	Error          error
	CompletionTime time.Time
}

Task represents a single task with an ID, a function to execute, status, error, and completion time.

type TaskResult

type TaskResult struct {
	ID             string      `json:"id"`
	Status         TaskStatus  `json:"status"`
	Error          error       `json:"error"`
	CompletionTime time.Time   `json:"completion_time"`
	Result         interface{} `json:"result"`
}

type TaskStatus

type TaskStatus string

TaskStatus represents the status of a task.

const (
	Pending  TaskStatus = "pending"
	Success  TaskStatus = "success"
	Error    TaskStatus = "error"
	Archived TaskStatus = "archived"
)

Jump to

Keyboard shortcuts

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