Last active
May 22, 2024 15:16
-
-
Save reubenmiller/4e28e8403fe0c54b7461ac7d1d6838c2 to your computer and use it in GitHub Desktop.
draft: thin-edge.io workflow schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"$id": "https://thin-edge.io/workflow.json", | |
"title": "thin-edge.io workflow", | |
"description": "Workflows can be used to customize existing operations and add user defined processes which are coordinated by thin-edge.io", | |
"type": "object", | |
"definitions": { | |
"on_state": { | |
"oneOf": [ | |
{ | |
"type": "object", | |
"properties": { | |
"status": { | |
"type": "string" | |
}, | |
"reason": { | |
"type": "string", | |
"title": "Reason for moving to the next state", | |
"description": "The default reason to be used if no reason is provided in the script's standard output" | |
} | |
}, | |
"default": { | |
"status": "successful" | |
} | |
}, | |
{ | |
"type": "string" | |
} | |
] | |
}, | |
"on_exit": { | |
"type": "object", | |
"description": "Next states to move to based on different exit codes", | |
"properties": { | |
"0": { | |
"$ref": "#/definitions/on_state" | |
}, | |
"_": { | |
"$ref": "#/definitions/on_state" | |
} | |
}, | |
"patternProperties": { | |
"^\\d+$": { | |
"$ref": "#/definitions/on_state" | |
}, | |
"^_$": { | |
"$ref": "#/definitions/on_state" | |
}, | |
"^\\d+-\\d+$": { | |
"$ref": "#/definitions/on_state" | |
} | |
}, | |
"additionalProperties": { | |
"$ref": "#/definitions/state" | |
}, | |
"default": { | |
"0": "successful" | |
} | |
}, | |
"on_stdout": { | |
"description": "List of acceptable states which can be sent via the standard output of the script", | |
"type": "array", | |
"items": { | |
"type": "string" | |
} | |
}, | |
"on_error": { | |
"description": "What to do on errors", | |
"oneOf": [ | |
{ | |
"type": "object", | |
"properties": { | |
"status": { | |
"type": "string", | |
"default": "failed" | |
}, | |
"reason": { | |
"type": "string" | |
} | |
}, | |
"required": [ | |
"status" | |
], | |
"default": { | |
"status": "failed" | |
} | |
}, | |
{ | |
"type": "string" | |
} | |
] | |
}, | |
"action": { | |
"type": "string", | |
"anyOf": [ | |
{ | |
"const": "builtin", | |
"title": "Use builtin action", | |
"description": "builtin is used when a builtin operation is overwritten by a custom workflow and indicates that for that state the builtin action has to be applied" | |
}, | |
{ | |
"const": "proceed", | |
"title": "Proceed to next action", | |
"description": "a no-op action, simply proceeding to the next state, which is useful when a builtin operation is customized but no specific behavior has to be added on a workflow extension point" | |
}, | |
{ | |
"const": "await-operation-completion", | |
"title": "Wait for an operation to complete", | |
"description": "Should only be called from a state which previously used the 'operation' property to create a local thin-edge.io operation" | |
}, | |
{ | |
"const": "cleanup", | |
"title": "Wait for command to be acknowledged", | |
"description": "marks the terminal state of the workflow where the command has been fully processed and where the original requester is expected to clean up the command retained message storing its state" | |
} | |
] | |
}, | |
"background_script": { | |
"type": "object", | |
"properties": { | |
"background_script": { | |
"type": "string", | |
"title": "Background script to execute" | |
}, | |
"timeout_second": { | |
"type": "number", | |
"title": "Timeout in seconds", | |
"description": "The number of second given to the action to execute" | |
}, | |
"on_exec": { | |
"$ref": "#/definitions/on_state", | |
"description": "defines the next state once the action has been launched in the background. The action outcome will have to be observed in this on_exec state" | |
}, | |
"on_error": { | |
"$ref": "#/definitions/on_error", | |
"description": "defines the next state when the action failed" | |
} | |
}, | |
"required": [ | |
"background_script", | |
"on_exec" | |
] | |
}, | |
"script": { | |
"type": "object", | |
"properties": { | |
"script": { | |
"type": "string", | |
"title": "Script to execute" | |
}, | |
"timeout_second": { | |
"type": "number", | |
"title": "Timeout in seconds", | |
"description": "The number of second given to the action to execute" | |
}, | |
"on_stdout": { | |
"$ref": "#/definitions/on_stdout" | |
}, | |
"on_success": { | |
"$ref": "#/definitions/on_state", | |
"description": "defines the next state when the action is successful" | |
}, | |
"on_error": { | |
"$ref": "#/definitions/on_error", | |
"description": "defines the next state when the action failed" | |
}, | |
"on_kill": { | |
"$ref": "#/definitions/on_state", | |
"description": "defines next state if the script is killed due to receiving a signal e.g. SIGTERM or SIGKILL" | |
}, | |
"on_timeout": { | |
"$ref": "#/definitions/on_state", | |
"description": "defines the next state when the action is not be completed within the time limit" | |
}, | |
"on_exit": { | |
"$ref": "#/definitions/on_exit" | |
} | |
}, | |
"oneOf": [ | |
{ | |
"required": [ | |
"script", | |
"on_success" | |
] | |
}, | |
{ | |
"required": [ | |
"script", | |
"on_exit" | |
] | |
} | |
] | |
}, | |
"builtin_action": { | |
"type": "object", | |
"properties": { | |
"action": { | |
"$ref": "#/definitions/action" | |
}, | |
"timeout_second": { | |
"type": "number", | |
"title": "Timeout in seconds", | |
"description": "The number of second given to the action to execute" | |
}, | |
"on_stdout": { | |
"$ref": "#/definitions/on_stdout" | |
}, | |
"on_exec": { | |
"$ref": "#/definitions/on_state", | |
"description": "defines the next state once the action has been launched in the background. The action outcome will have to be observed in this on_exec state" | |
}, | |
"on_success": { | |
"$ref": "#/definitions/on_state", | |
"description": "defines the next state when the action is successful" | |
}, | |
"on_error": { | |
"$ref": "#/definitions/on_error", | |
"description": "defines the next state when the action failed" | |
}, | |
"on_kill": { | |
"$ref": "#/definitions/on_state", | |
"description": "" | |
}, | |
"on_timeout": { | |
"$ref": "#/definitions/on_state", | |
"description": "defines the next state when the action is not be completed within the time limit" | |
}, | |
"on_exit": { | |
"$ref": "#/definitions/on_exit" | |
} | |
}, | |
"required": [ | |
"action" | |
] | |
}, | |
"operation": { | |
"type": "object", | |
"properties": { | |
"operation": { | |
"type": "string", | |
"title": "thin-edge.io operation to trigger" | |
}, | |
"on_exec": { | |
"$ref": "#/definitions/on_state", | |
"description": "defines the next state once the action has been launched in the background. The action outcome will have to be observed in this on_exec state" | |
} | |
}, | |
"required": [ | |
"operation" | |
] | |
}, | |
"state": { | |
"oneOf": [ | |
{ | |
"$ref": "#/definitions/script" | |
}, | |
{ | |
"$ref": "#/definitions/background_script" | |
}, | |
{ | |
"$ref": "#/definitions/builtin_action" | |
}, | |
{ | |
"$ref": "#/definitions/operation" | |
} | |
] | |
} | |
}, | |
"properties": { | |
"operation": { | |
"type": "string", | |
"pattern": "^[A-Za-z0-9_-]+$", | |
"default": "custom_operation" | |
}, | |
"timeout_second": { | |
"type": "number", | |
"title": "Default timeout in seconds to use for each state", | |
"description": "Default timeout for each state. If set to 0, then no timeout will be applied", | |
"default": 0 | |
}, | |
"on_error": { | |
"allOf": [ | |
{ | |
"$ref": "#/definitions/on_state" | |
}, | |
{ | |
"description": "Default on_error action to be used by each state" | |
} | |
] | |
}, | |
"init": { | |
"$ref": "#/definitions/state", | |
"default": { | |
"action": "proceed", | |
"on_success": "successful" | |
} | |
}, | |
"scheduled": { | |
"$ref": "#/definitions/state", | |
"default": { | |
"action": "proceed", | |
"on_success": "executing" | |
} | |
}, | |
"executing": { | |
"$ref": "#/definitions/state", | |
"default": { | |
"action": "proceed", | |
"on_success": "successful", | |
"on_error": "failed" | |
} | |
}, | |
"successful": { | |
"$ref": "#/definitions/state", | |
"default": { | |
"action": "cleanup" | |
} | |
}, | |
"failed": { | |
"$ref": "#/definitions/state", | |
"default": { | |
"action": "cleanup" | |
} | |
} | |
}, | |
"required": [ | |
"operation", | |
"init", | |
"successful", | |
"failed" | |
], | |
"additionalProperties": { | |
"$ref": "#/definitions/state" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment