Documentation ¶
Index ¶
- Constants
- Variables
- func AmendID(id string) data.ImmutableKeyValue
- func NewTaskGroup(options ...data.ImmutableKeyValue) (*taskGroup, fail.Error)
- func NewTaskGroupWithContext(ctx context.Context, options ...data.ImmutableKeyValue) (*taskGroup, fail.Error)
- func NewTaskGroupWithParent(parentTask Task, options ...data.ImmutableKeyValue) (*taskGroup, fail.Error)
- type Task
- func NewTask() (Task, fail.Error)
- func NewTaskWithContext(ctx context.Context, options ...data.ImmutableKeyValue) (Task, fail.Error)
- func NewTaskWithParent(parentTask Task, options ...data.ImmutableKeyValue) (Task, fail.Error)
- func NewUnbreakableTask() (Task, fail.Error)
- func RootTask() (rt Task, ferr fail.Error)
- func TaskFromContext(ctx context.Context) (Task, fail.Error)
- func TaskFromContextOrVoid(ctx context.Context) (Task, fail.Error)
- func VoidTask() (Task, fail.Error)
- type TaskAction
- type TaskCore
- type TaskGroup
- type TaskGroupGuard
- type TaskGroupResult
- type TaskGuard
- type TaskParameters
- type TaskResult
- type TaskStatus
Constants ¶
const (
KeyForTaskInContext taskContextKey = "task"
)
Variables ¶
var ( // FailEarly tells the TaskGroup to fail as soon as a child fails FailEarly = data.NewImmutableKeyValue("fail", "early") // FailLately tells the TaskGroup to end all children before determine if TaskGroup has failed FailLately = data.NewImmutableKeyValue("fail", "lately") )
var (
InheritParentIDOption = data.NewImmutableKeyValue(keywordInheritParentIDOption, true)
)
Functions ¶
func AmendID ¶
func AmendID(id string) data.ImmutableKeyValue
AmendID returns a data.ImmutableKeyValue containing string to add to task ID to be used as option on NewXXX functions that accept such options
func NewTaskGroup ¶
func NewTaskGroup(options ...data.ImmutableKeyValue) (*taskGroup, fail.Error)
NewTaskGroup ...
func NewTaskGroupWithContext ¶
func NewTaskGroupWithContext(ctx context.Context, options ...data.ImmutableKeyValue) (*taskGroup, fail.Error)
NewTaskGroupWithContext ...
func NewTaskGroupWithParent ¶
func NewTaskGroupWithParent(parentTask Task, options ...data.ImmutableKeyValue) (*taskGroup, fail.Error)
NewTaskGroupWithParent ...
Types ¶
type Task ¶
Task is the interface of a task running in goroutine, allowing to identity (indirectly) goroutines
func NewTaskWithContext ¶
NewTaskWithContext creates an instance of Task with context
func NewTaskWithParent ¶
NewTaskWithParent creates a subtask Such a task can be aborted if the parent one can be
func NewUnbreakableTask ¶
NewUnbreakableTask is a new task that cannot be aborted by default (but this can be changed with IgnoreAbortSignal(false))
func TaskFromContext ¶
TaskFromContext extracts the task instance from context returns:
- Task, nil: Task found in 'ctx'
- nil, *fail.ErrNotAvailable: there is no Task value in 'ctx'
- nil, *fail.ErrInconsistent: value stored as Task in "ctx' is not of type Task
- nil, *ErrInvalidParameter: 'ctx' is nil
func TaskFromContextOrVoid ¶ added in v21.11.1
TaskFromContextOrVoid extracts the task instance from context. If there is no task in the context, returns a VoidTask() returns:
- Task, nil: Task found in 'ctx' or VoidTask() is returned
type TaskAction ¶
type TaskAction func(t Task, parameters TaskParameters) (TaskResult, fail.Error)
TaskAction defines the type of the function that can be started by a Task. NOTE: you have to check if task is aborted inside this function using method t.ErrAborted(),
to be able to stop the process when task is aborted (no matter what the abort reason is), and permit ending properly. Otherwise, this may lead to goroutine leak (there is no good way to stop forcibly a goroutine).
Example: task.Start(func(task concurrency.Task, p TaskParameters) (concurrency.TaskResult, fail.Error) { ...
for { if task.ErrAborted() { break // or return } ... } return nil }, nil)
type TaskCore ¶
type TaskCore interface { Abort() fail.Error AbortWithCause(fail.Error) fail.Error Abortable() (bool, fail.Error) Aborted() bool DisarmAbortSignal() func() ID() (string, fail.Error) Signature() string Status() (TaskStatus, fail.Error) Context() context.Context LastError() (error, fail.Error) Result() (TaskResult, fail.Error) SetID(string) fail.Error Run(fn TaskAction, params TaskParameters, options ...data.ImmutableKeyValue) (TaskResult, fail.Error) Start(fn TaskAction, params TaskParameters, options ...data.ImmutableKeyValue) (Task, fail.Error) StartWithTimeout(fn TaskAction, params TaskParameters, timeout time.Duration, options ...data.ImmutableKeyValue) (Task, fail.Error) }
TaskCore is the interface of core methods to control Task and TaskGroup
type TaskGroup ¶
type TaskGroup interface { TaskCore TaskGuard TaskGroupGuard GroupStatus() (map[TaskStatus][]string, fail.Error) }
TaskGroup is the task group interface
type TaskGroupGuard ¶
type TaskGroupGuard interface { Started() (uint, fail.Error) TryWaitGroup() (bool, TaskGroupResult, fail.Error) WaitGroup() (TaskGroupResult, fail.Error) WaitGroupFor(time.Duration) (bool, TaskGroupResult, fail.Error) }
TaskGroupGuard is the task group interface defining method to wait the TaskGroup
type TaskGroupResult ¶
type TaskGroupResult = map[string]TaskResult
TaskGroupResult is a map of the TaskResult of each task The index is the ID of the sub-Task running the action.
type TaskGuard ¶
type TaskGuard interface { TryWait() (bool, TaskResult, fail.Error) Wait() (TaskResult, fail.Error) WaitFor(time.Duration) (bool, TaskResult, fail.Error) }
TaskGuard ...
type TaskStatus ¶
type TaskStatus int
TaskStatus ...
const ( UNKNOWN TaskStatus = iota // status is unknown READY // the task is ready to start RUNNING // the task is running DONE // the task has run and is done ABORTED // the task has been aborted TIMEOUT // the task ran out of time )