← All Examples

hello-workflow

The simplest possible assay workflow: one activity that says hello.

What it does

GreetWorkflow(input)
  └─> activity "greet"  →  { message = "hello, " .. input.who }
  return { greeting = ... }

Run

In one terminal:

assay serve

In another, from this directory:

assay run worker.lua

In a third, start a workflow:

curl -X POST http://localhost:8080/api/v1/workflows \
  -H 'Content-Type: application/json' \
  -d '{
    "workflow_type": "GreetWorkflow",
    "workflow_id": "hello-1",
    "task_queue": "default",
    "input": {"who": "world"}
  }'

Within ~1 second:

curl -s http://localhost:8080/api/v1/workflows/hello-1 | jq .result
# "{\"greeting\":\"hello, world\"}"

The dashboard at http://localhost:8080/workflow/ shows it under Workflows; click the row to see the event timeline (WorkflowStartedActivityScheduledActivityCompletedWorkflowCompleted).

Source

worker.lua

-- hello-workflow — smallest possible assay workflow.
-- Run: assay run worker.lua  (with `assay serve` running on :8080)

local workflow = require("assay.workflow")

workflow.connect(env.get("ASSAY_ENGINE_URL") or "http://localhost:8080")

workflow.define("GreetWorkflow", function(ctx, input)
    local r = ctx:execute_activity("greet", { who = input.who })
    return { greeting = r.message }
end)

workflow.activity("greet", function(ctx, input)
    return { message = "hello, " .. input.who }
end)

log.info("hello-workflow worker ready — POST a workflow to start one")
workflow.listen({ queue = "default" })