task

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteExpiredCompleted

func DeleteExpiredCompleted(ctx context.Context, db *sql.DB) error

DeleteExpiredCompleted deletes completed tasks that have an expiration date in the past.

Types

type Completed

type Completed struct {
	// ID is the Task ID
	ID string

	// Queue is the name of the queue this Task belongs to.
	Queue string

	// Task is the task data.
	Task []byte

	// Attempts are the amount of times this Task was executed.
	Attempts int

	// Succeeded indicates if the Task execution was a success.
	Succeeded bool

	// LastDuration is the last execution duration.
	LastDuration time.Duration

	// ExpiresAt is when this record should be removed from the database.
	// If omitted, the record should not be removed.
	ExpiresAt *time.Time

	// CreatedAt is when the Task was originally created.
	CreatedAt time.Time

	// LastExecutedAt is the last time this Task executed.
	LastExecutedAt time.Time

	// Error is the error message provided by the Task processor.
	Error *string
}

Completed is a completed task.

func (*Completed) InsertTx

func (c *Completed) InsertTx(ctx context.Context, tx *sql.Tx) error

InsertTx inserts a completed task as part of a database transaction.

type CompletedTasks

type CompletedTasks []*Completed

CompletedTasks contains multiple completed tasks.

func GetCompletedTasks

func GetCompletedTasks(ctx context.Context, db *sql.DB, query string, args ...any) (CompletedTasks, error)

GetCompletedTasks loads completed tasks from the database using a given query and arguments.

type Task

type Task struct {
	// ID is the Task ID
	ID string

	// Queue is the name of the queue this Task belongs to.
	Queue string

	// Task is the task data.
	Task []byte

	// Attempts are the amount of times this Task was executed.
	Attempts int

	// WaitUntil is the time the task should not be executed until.
	WaitUntil *time.Time

	// CreatedAt is when the Task was originally created.
	CreatedAt time.Time

	// LastExecutedAt is the last time this Task executed.
	LastExecutedAt *time.Time

	// ClaimedAt is the time this Task was claimed for execution.
	ClaimedAt *time.Time
}

Task is a task that is queued for execution.

func (*Task) DeleteTx

func (t *Task) DeleteTx(ctx context.Context, tx *sql.Tx) error

DeleteTx deletes a task as part of a database transaction.

func (*Task) Fail

func (t *Task) Fail(ctx context.Context, db *sql.DB, waitUntil time.Time) error

Fail marks a task as failed in the database and queues it to be executed again.

func (*Task) InsertTx

func (t *Task) InsertTx(ctx context.Context, tx *sql.Tx) error

InsertTx inserts a task as part of a database transaction.

type Tasks

type Tasks []*Task

Tasks are a slice of tasks.

func GetScheduledTasks

func GetScheduledTasks(ctx context.Context, db *sql.DB, deadline time.Time, limit int) (Tasks, error)

GetScheduledTasks loads the tasks that are next up to be executed in order of execution time. It's important to note that this does not filter out tasks that are not yet ready based on their wait time. The deadline provided is used to include tasks that have been claimed if that given amount of time has elapsed.

func GetTasks

func GetTasks(ctx context.Context, db *sql.DB, query string, args ...any) (Tasks, error)

GetTasks loads tasks from the database using a given query and arguments.

func (Tasks) Claim

func (t Tasks) Claim(ctx context.Context, db *sql.DB) error

Claim updates a Task in the database to indicate that it has been claimed by a processor to be executed.

Jump to

Keyboard shortcuts

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