Skip to content

Instantly share code, notes, and snippets.

@LindsayHill
Created June 28, 2018 21:54
Show Gist options
  • Save LindsayHill/08d100374aae5508bf4ccd2571eaab10 to your computer and use it in GitHub Desktop.
Save LindsayHill/08d100374aae5508bf4ccd2571eaab10 to your computer and use it in GitHub Desktop.
version: 1.0
description: >
A sample workflow that demonstrates how to handle rollback and retry on error. In this example,
the workflow will loop until the file /tmp/done exists. A parallel task will wait for some time
before creating the file. When completed, /tmp/done will be deleted.
vars:
- file: /tmp/<% str(random(1000000, 9999999)) %>
tasks:
init:
action: core.local cmd="rm -rf <% ctx().file %>"
next:
- when: <% succeeded() %>
do: check, create
check:
action: core.local
input:
cmd: >
echo 'Do something useful here.';
if [ ! -e <% ctx().file %> ]; then exit 1; fi
next:
- when: <% succeeded() %>
do: delete
- when: <% failed() %>
do: rollback
rollback:
action: core.local
input:
cmd: >
echo 'Rollback something here.';
sleep 1;
next:
- when: <% succeeded() %>
do: check
create:
action: core.local cmd="sleep 3; touch <% ctx().file %>"
delete:
action: core.local cmd="rm -f <% ctx().file %>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment