Just some pointers with some of the issues from your workflow:
await-operation-completion should only be used when you’ve called another workflow via the operation property - see docs
on_exec is used for background execution, e.g. when background_script is used - see docs
It is best practice to use the [executing] state (so that the user has clear indication when the workflow is starting to execute)
I’ve rewritten your workflow by just using the script property (as you don’t need anything fancy here like background scripts).
Use check to run the conditional logic in one place, which just checks if the user provided a c8yUrl or not, and then decides which state should be executed next (without executing anything itself).
Use sudo tedge reconnect c8y over tedgectl…as the mapper will restart the appropriate services using the init system abstraction…Though you might need to add tedge to sudoers list of allowed commands
Split each action into different states. It is easier to read and work out where something failed.
operation = "config_tedge"
on_failure = "failed"
[init]
action = "proceed"
on_success = "executing"
[executing]
action = "proceed"
on_success = "check"
[check]
script = "sh -c '[ -n ${.payload.c8yUrl} ]'"
on_success = { status = "configure", reason = "configure url"}
on_error = { status = "successful", reason = "c8yUrl is not provided, so nothing to do"}
# Alternatively, you could fail the operation if you the c8yUrl is required
# on_exit._ = { status = "failed", reason = "c8yUrl was not provided. c8yUrl is a required argument"}
[configure]
script = "tedge config set c8y.url ${.payload.c8yUrl}"
on_success = "reconnect"
[reconnect]
script = "sudo tedge reconnect c8y"
on_success = "successful"
[successful]
action = "cleanup"
[failed]
action = "cleanup"
Sorry I didn’t read the full requirements…but a lot of the above comments still stand:
But this is an amended workflow which conditionally runs tedge config set c8y.url if the user provides the c8yUrl in the command’s payload, if not then it only restarts the mapper (it does not configure it).