Skip to content

Instantly share code, notes, and snippets.

@ccarvalho-eng
Last active May 13, 2026 17:35
Show Gist options
  • Select an option

  • Save ccarvalho-eng/2a3fff0284eb55edf3de6f437b16857d to your computer and use it in GitHub Desktop.

Select an option

Save ccarvalho-eng/2a3fff0284eb55edf3de6f437b16857d to your computer and use it in GitHub Desktop.
defmodule MiddleEarth.Workflows.RingQuest do
use SquidMesh.Workflow
workflow do
trigger :leave_shire do
manual()
payload do
field :ring_bearer, :string, default: "Frodo"
field :snack_count, :integer, default: 7
field :has_eagle_backup, :boolean, default: false
end
end
step :pack_lembas, Hobbiton.Steps.PackLembas,
input: [:snack_count],
output: :provisions,
transaction: :repo
step :announce_trip, :log,
message: "Leaving the Shire with suspicious jewelry",
level: :info
step :wait_for_gandalf, :wait, duration: 5_000
approval_step :council_votes_on_plan, output: :council
step :cross_moria, Fellowship.Steps.CrossMoria,
input: [:ring_bearer, :provisions, :council],
output: :moria_result,
retry: [
max_attempts: 3,
backoff: [type: :exponential, min: 1_000, max: 10_000]
]
step :panic_at_balrog, Fellowship.Steps.PanicAtBalrog
step :toss_ring, Mordor.Steps.TossRing, irreversible: true
transition :pack_lembas, on: :ok, to: :announce_trip
transition :announce_trip, on: :ok, to: :wait_for_gandalf
transition :wait_for_gandalf, on: :ok, to: :council_votes_on_plan
transition :council_votes_on_plan, on: :ok, to: :cross_moria
transition :council_votes_on_plan, on: :error, to: :panic_at_balrog
transition :cross_moria, on: :ok, to: :toss_ring
transition :cross_moria, on: :error, to: :panic_at_balrog
transition :toss_ring, on: :ok, to: :complete
transition :panic_at_balrog, on: :ok, to: :complete
end
end
defmodule Gondor.Workflows.LightBeacons do
use SquidMesh.Workflow
workflow do
trigger :nightly_beacon_check do
cron "0 21 * * *", timezone: "Etc/UTC"
payload do
field :steward_mood, :string, default: "dramatic"
field :orc_count, :integer, default: 9001
end
end
step :inspect_hilltops, Gondor.Steps.InspectHilltops, output: :hilltops
step :light_first_beacon, Gondor.Steps.LightBeacon,
input: [:hilltops],
compensate: Gondor.Steps.ExtinguishBeacon,
retry: [max_attempts: 5]
step :log_success, :log, message: "Gondor calls for aid"
transition :inspect_hilltops, on: :ok, to: :light_first_beacon
transition :light_first_beacon, on: :ok, to: :log_success
transition :log_success, on: :ok, to: :complete
end
end
{:ok, run} =
SquidMesh.start_workflow(MiddleEarth.Workflows.RingQuest, :leave_shire, %{
"ring_bearer" => "Frodo",
"snack_count" => 11
})
{:ok, paused} = SquidMesh.inspect_run(run.id, include_history: true)
{:ok, resumed} =
SquidMesh.approve_run(run.id, %{
actor: "elrond",
note: "Fine, the smallest person gets the worst errand."
})
SquidMesh.explain_run(resumed.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment