Documentation ¶
Overview ¶
Package taskengine can be used to concurrently execute a set of tasks assigned to multiple different workers.
A Task represents a unit of work to be executed. Each task can be assigned to one or more workers. Two tasks are considered equivalent if they have the same TaskID. Note that tasks with the same TaskID can be different object with different information; this allows a task object assigned to a worker to contain information specific to that worker.
Each Worker has a WorkFunc that performs the task. Multiple instances of the same worker can be used to concurrently execute different tasks assign to the worker.
The execution mode of the task is managed by the engine.Mode parameters:
- FirstSuccessOrLastError: For each task it returns only one result: the first success or the last error. If a task can be handled by two or more workers, only the first success result is returned. The remaining job for same task are skipped.
- UntilFirstSuccess: For each task returns the (not successfull) result of all the workers: after the first success the other requests are cancelled.
- All: For each task returns the result of all the workers. Multiple success results can be returned.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Mode ¶
type Mode int
Mode of execution for each task.
const ( // For each task returns only one result: // the first success or the last error. FirstSuccessOrLastError Mode = iota // For each task returns the results until the first success: // after the first success the other requests are cancelled and not returned. // At most one success is returned. UntilFirstSuccess // For each task returns the result of all the workers. // Multiple success results can be returned. // After the first success, the remaining requests are cancelled. All )
Values of mode of execution for each task.
type Result ¶
type Result interface { // Success return true in case of a success response. // In this case no other Request will be worked for the same Job. Success() bool }
Result is the interface that must be matched by the output of the Work function.
type Task ¶
type Task interface {
TaskID() TaskID
}
Task is a unit of work that can be executed by a worker Two or more task with the same TaskID are equivalent and possibly only one will be executed. Two or more task with the same TaskID can contain different information usefull for a specific worker.
type WorkFunc ¶
WorkFunc is the worker function. - context: the context - int: the instance id of the worker - Task: the task to be eecuted
type Worker ¶
type Worker struct { // Unique ID of the worker WorkerID WorkerID // Number of worker instances. Must be greater or equal 1 Instances int // The work function Work WorkFunc }
Worker is the unit (identified by WorkerID) that receives the Requests and executes a specific WorkFunc function to return the Responses. The Instances parameters represents the number of instances of each worker
type WorkerTasks ¶
WorkerTasks is a map representing the tasks list of each worker
func (WorkerTasks) Clone ¶
func (wts WorkerTasks) Clone() WorkerTasks
Clone method returns a cloned copy of the WorkerTasks object.