goodjob

package
v0.0.0-...-c72f787 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job interface {
	// GetID - return JobID
	GetID() JobID
	// GetTasks - return Job's tasks
	GetTasks() []Task
	// GetTaskArgs - return arguments that supposed to be passed to it during execution
	GetTaskArgs(taskID TaskID) []*TaskArg
	// GetVisible - is job visible for Queue processors
	GetVisible() bool
	// SetVisible - set Job visible value
	SetVisible(visible bool)
	// GetLastTask - get last run Task
	GetLastTask() Task
	// SetLastTask - set last run Task
	SetLastTask(task Task)
	// GetLastTaskPos - get position of last run Task
	GetLastTaskPos() int
	// SetLastTaskPos - set position of last run Task
	SetLastTaskPos(pos int)
	// GetLastTaskResult - get TaskResult of last run Task
	GetLastTaskResult() *TaskResult
	// SetLastTaskResult - set TaskResult of last run Task
	SetLastTaskResult(result *TaskResult)
}

Job - unit of work that consist of many tasks that have to be executed in a sequential order

type JobArg

type JobArg struct {
	Name  string
	Value any
}

type JobID

type JobID string

JobID - unique id of a Job

type JobResult

type JobResult struct {
	ID    JobID
	Value any
	Err   error
}

type JobResultsStorage

type JobResultsStorage interface {
	Put(result *JobResult) error
	Get(id JobID) (*JobResult, error)
}

type Processor

type Processor interface {
	// Start - starts the processor
	Start(args ...*ProcessorArg) error
	// Stop - stops the processor
	Stop(args ...*ProcessorArg) error
	// AddJob - adds job to be processed
	AddJob(job Job, args ...*ProcessorArg) error
	// GetJobResult - retrieves job result. If job result not found, an error is returned
	GetJobResult(id JobID, args ...*ProcessorArg) (*JobResult, error)
}

Processor - is a worker that accepts jobs for execution, executes them and allows to get result of executed jobs.

type ProcessorArg

type ProcessorArg struct {
	Name  string
	Value any
}

type Queue

type Queue interface {
	// AddJob - adds to Job to queue
	AddJob(job Job, args ...*QueueArg) error
	// GetNextJob - returns Job from the top of the queue.
	GetNextJob(args ...*QueueArg) (Job, error)
	// RemoveJob - removes Job from the queue
	RemoveJob(id JobID, args ...*QueueArg) error
	// SetJobVisibility - sets Job visibility inside the queue.
	// If Job visibility is set to false, consumers of the queue would not be able to get it via a call to GetNextJob
	SetJobVisibility(id JobID, visible bool, args ...*QueueArg) error
}

Queue - basic interface for Job queue.

type QueueArg

type QueueArg struct {
	Name  string
	Value any
}

type RetryableJob

type RetryableJob interface {
	Job
	// GetTasksToRetry - return a list of tasks that need to be retried
	GetTasksToRetry() []Task
	// IncreaseRetryCount - increase retry attempts counter for specific Task
	IncreaseRetryCount(taskID TaskID)
	// RetryThresholdReached - is retry threshold reached for specific Task, if true retry attempts should be stopped
	RetryThresholdReached(taskID TaskID) bool
}

RetryableJob - a Job that can be retried from last unsuccessful Task

type RetryableRevertibleJob

type RetryableRevertibleJob interface {
	RetryableJob
	RevertibleJob
}

RetryableRevertibleJob - a Job that can be both reverted and retried in both directions of execution

type RevertibleJob

type RevertibleJob interface {
	Job
	// GetTasksToRevert - get list of task that can be reverted in case of an error encountered during Job execution
	GetTasksToRevert() []RevertibleTask
	// GetRevertState - is Job in the revert state. If true previous successful revertible tasks should be attempted to be reverted
	GetRevertState() bool
	// SetRevertState - set value for Job revert state. If set to true previous successful revertible tasks should be attempted to be reverted
	SetRevertState(revert bool)
}

RevertibleJob - a Job that can be reverted in case of an error encountered during Job execution

type RevertibleTask

type RevertibleTask interface {
	Task
	// Revert - revert results of Task execution
	Revert(args ...*TaskArg) (result *TaskResult)
}

RevertibleTask - a task that can be reverted

type Task

type Task interface {
	// GetID - get TaskID of a task
	GetID() TaskID
	// GetJobID - get JobID of a Job that task belongs to
	GetJobID() JobID
	// Exec - execute task with optional arguments
	Exec(args ...*TaskArg) *TaskResult
}

Task - an atomic unit of work within a job

type TaskArg

type TaskArg struct {
	// Name - argument name
	Name string
	// Value - argument value
	Value any
	// ValueFrom - TaskID of a task which result is supposed to be used as a value
	ValueFrom TaskID
}

TaskArg - argument for a Task

type TaskID

type TaskID string

TaskID - id of a task

type TaskResult

type TaskResult struct {
	// JobID - id of a parent Job
	JobID JobID
	// TaskID - id of a Task
	TaskID TaskID
	// Value - actual task result
	Value any
	// Err - error that have occurred during Task execution
	Err error
}

TaskResult - result of Task execution

type TaskResultsStorage

type TaskResultsStorage interface {
	Put(result *TaskResult) error
	Get(jobID JobID, taskID TaskID) (*TaskResult, error)
}

Jump to

Keyboard shortcuts

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