Documentation
¶
Overview ¶
Package workflow provides a simple engine to sequentially run groups of shell tasks, while providing a websocket to monitor progress.
Workflows are defined using a yaml file which contains variables declaration and groups of tasks.
Tasks shell scripts can use functions like `output` and `progress` to publish meaningful information to the websocket.
Tasks can have an optional relative `weight` value so a progress expressed in percent is added in the status message.
Example ¶
This workflow declares a variable `OS` with the output of `uname` command, then it defines two groups of tasks, one for Linux and one for Darwin.
Groups are being skipped based on the content of `OS`
vars:
OS: uname
groups:
- id: linuxGroup
skip_cmd: |
[ "$OS" != "Linux" ]
tasks:
- id: task1
weight: 50
cmd: |
output `ip a s eth0|grep inet`
- id: darwinGroup
skip_cmd: |
[ "$OS" != "Darwin" ]
tasks:
- id: task1
weight: 50
cmd: |
output `ifconfig en0|grep "inet "`
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( WorkflowErrorNoGroups = fmt.Errorf("no group definitions found") WorkflowErrorInvalidVars = fmt.Errorf("invalid variables definition") WorkflowErrorGroupMissingId = fmt.Errorf("group missing id") WorkflowErrorGroupMissingTasks = fmt.Errorf("group missing tasks") WorkflowErrorTaskMissingId = fmt.Errorf("task missing id") WorkflowErrorTaskMissingCommand = fmt.Errorf("task missing cmd") WorkflowErrorNotFinished = fmt.Errorf("workflow not finished") )
Errors definitions
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
Id string `json:"id"`
Tasks []*Task `json:"tasks"`
Skip bool `json:"skip"`
Percent float64 `json:"percent"`
Started bool `json:"started"`
Finished bool `json:"finished"`
LastMessage string `json:"lastMessage"`
Error string `json:"error"`
// contains filtered or unexported fields
}
Group represents a group of tasks in a workflow. It will give informations about the execution state like completion percentage, any error that occurred and the last message received from the tasks. Groups can be skipped if the command in skip_cmd from the yaml definition returns a zero status code.
type Status ¶
type Status struct {
// Definition is a copy of the original workflow definition
// For example, if you defined a multi step workflow and the original
// definition file is changed, this will not be updated.
Definition map[string]any `json:"definition"`
// Vars contains all the values for variables defined in the workflow
Vars map[string]string `json:"vars"`
// Groups contains all the groups defined in the workflow, which in turn
// contains all the tasks.
Groups []*Group `json:"groups"`
Started bool `json:"started"` // Workflow has been started
Finished bool `json:"finished"` // Workflow has finished
Percent int `json:"percent"` // Workflow progress in percent, assuming all tasks have weights defined
LastMessage string `json:"lastMessage"` // The last message returned by a task using `output`
CurrentGroup string `json:"currentGroup"` // Currently running group
CurrentTask string `json:"currentTask"` // Currently running task
Error string `json:"error,omitempty"` // Last error
}
Status all the informations related to the workflow run.
type Task ¶
type Task struct {
Id string `json:"id"`
Cmd string `json:"cmd"`
Weight int `json:"weight"`
Exits bool `json:"exits"`
Started bool `json:"started"`
Finished bool `json:"finished"`
Percent float64 `json:"percent"`
Error string `json:"error"`
// contains filtered or unexported fields
}
A Task represents a command to be run in the workflow.
You can specify a weight for all tasks to have a meaningful progress percentage at the group and at the workflow level. For example, a task that is known to execute very quickly can be given a weight of 5, while a task that is known to execute for a long time can be given a weight of 100.
If `exits` is set to true, the running program will exit after the task, and next time the workflow is run with [Continue()] it will pick up right after this task, marking it as finished. The is useful for workflows that performs OS reboot or self upgrades.
type Workflow ¶
type Workflow struct {
Status Status // Status of the current workflow
sync.Mutex
// contains filtered or unexported fields
}
func New ¶
New returns a new Workflow with definition at definitionPath and status file to be written at statusFilePath as well as a http.HandlerFunc for handling websocket connections.
func (*Workflow) Abort ¶
func (w *Workflow) Abort()
Abort kills current tasks and stops workflow execution
func (*Workflow) Continue ¶
Continue is used instead of [Start] when a status file already exists after a previous unfinished run. If the statufile does not exists, it will return a file not found error.