runtaskbackground

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

README

run_task_background Task

Description

The run_task_background task facilitates the concurrent execution of a foreground task and a background task, with configurable dependencies and outcomes. This task is essential for simulating complex scenarios involving parallel processes.

Task Behavior

  • The task initiates both the foreground and background tasks simultaneously.
  • It continuously monitors the status and result of both tasks.
  • Upon completion of the foreground task, the run_task_background task also completes, and the background task is cancelled if it's still running.
  • The result of the run_task_background task mirrors the result of the foreground task. For instance, if the foreground task updates its result to "success", the run_task_background task will also set its result to "success".
  • The behavior following the completion of the background task is configurable based on the onBackgroundComplete setting.

Configuration Parameters

  • foregroundTask:
    The task that runs in the foreground. This is the primary task and is defined as per the standard task definition format.

  • backgroundTask:
    The task that runs in the background concurrently with the foreground task. It is also defined following the standard task definition format.

  • exitOnForegroundSuccess:
    If set to true, the run_task_background task will exit with a success result when the foreground task's result is set to "success". Note that this does not necessarily mean the foreground task has completed. If still running, both the background and foreground tasks will be cancelled.

  • exitOnForegroundFailure:
    If true, the task exits with a failure result when the foreground task's result is set to "failure". This does not imply the foreground task's completion. Both the background and foreground tasks will be cancelled if they are still running.

  • onBackgroundComplete:
    Specifies the action to take when the background task completes. Options are:

    • ignore: No action is taken.
    • fail: Exits the task with a failure result.
    • succeed: Exits the task with a success result.
    • failOrIgnore: Exits with a failure result if the background task fails, otherwise no action is taken.
  • newVariableScope:
    Determines if a new variable scope should be created for the foreground task. If false, the current scope is passed through. The background task always operates in a new variable scope, which inherits from the parent but does not propagate changes upwards.

Defaults

Default settings for the run_task_background task:

- name: run_task_background
  config:
    foregroundTask: {}
    backgroundTask: {}
    exitOnForegroundSuccess: false
    exitOnForegroundFailure: false
    onBackgroundComplete: "ignore"
    newVariableScope: false

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TaskName       = "run_task_background"
	TaskDescriptor = &types.TaskDescriptor{
		Name:        TaskName,
		Description: "Runs foreground and background task with configurable dependencies.",
		Config:      DefaultConfig(),
		NewTask:     NewTask,
	}
)

Functions

func NewTask

func NewTask(ctx *types.TaskContext, options *types.TaskOptions) (types.Task, error)

Types

type Config

type Config struct {
	ForegroundTask *helper.RawMessage `yaml:"foregroundTask" json:"foregroundTask"`
	BackgroundTask *helper.RawMessage `yaml:"backgroundTask" json:"backgroundTask"`

	ExitOnForegroundSuccess bool `yaml:"exitOnForegroundSuccess" json:"exitOnForegroundSuccess"`
	ExitOnForegroundFailure bool `yaml:"exitOnForegroundFailure" json:"exitOnForegroundFailure"`

	// action when background task stops
	// "ignore" - do nothing (default)
	// "fail" - exit with failure
	// "succeed" - exit with success
	// "failOrIgnore" - exit with failure if background task failed, ignore on success
	OnBackgroundComplete string `yaml:"onBackgroundComplete" json:"onBackgroundComplete"`

	NewVariableScope bool `yaml:"newVariableScope" json:"newVariableScope"`
}

func DefaultConfig

func DefaultConfig() Config

func (*Config) Validate

func (c *Config) Validate() error

type Task

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

func (*Task) Config

func (t *Task) Config() interface{}

func (*Task) Description

func (t *Task) Description() string

func (*Task) Execute

func (t *Task) Execute(ctx context.Context) error

func (*Task) LoadConfig

func (t *Task) LoadConfig() error

func (*Task) Logger

func (t *Task) Logger() logrus.FieldLogger

func (*Task) Name

func (t *Task) Name() string

func (*Task) Timeout

func (t *Task) Timeout() time.Duration

func (*Task) Title

func (t *Task) Title() string

Jump to

Keyboard shortcuts

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