A sample Phoenix LiveView application demonstrating the Durable workflow engine with human-in-the-loop approval capabilities.
- Document Processing Workflow: A multi-step workflow that validates, parses, and transforms documents
- Human-in-the-Loop: Workflow pauses and waits for manager approval before proceeding
- Real-time Updates: LiveView pages update in real-time as workflows progress
- Dashboard: Monitor all workflow executions with status tracking
- Approval Queue: Review and approve/reject pending workflow approvals
- Elixir 1.15+
- PostgreSQL 13+
-
Start the database (using Docker):
cd examples/phoenix_demo docker-compose up -dThis starts PostgreSQL on port 53412.
-
Install dependencies:
mix deps.get
-
Create and migrate the database:
mix ecto.create mix ecto.migrate
-
Start the server:
mix phx.server
-
Open in browser:
Navigate to http://localhost:4005 (the dashboard is mounted at http://localhost:4005/dashboard)
docker-compose downTo also remove the data volume:
docker-compose down -v- Click "New Workflow" in the navigation
- Enter a filename (e.g.,
report.pdf,data.csv) - Click "Start Workflow"
The document processing workflow goes through these steps:
- Validate Document - Checks the file extension is valid
- Parse Content - Extracts simulated content from the document
- Request Approval - Pauses and waits for human approval
- Transform Data - Processes the approved data
- Generate Report - Creates the final report
- Navigate to "Approvals" in the navigation
- You'll see pending approval requests
- Click "Review" to see document details
- Click "Approve" or "Reject"
When approved, the workflow resumes and completes. When rejected, it handles the rejection gracefully.
defmodule PhoenixDemo.Workflows.DocumentWorkflow do
use Durable
use Durable.Helpers
use Durable.Context
use Durable.Wait
workflow "process_document", timeout: hours(24) do
step :validate_document do
# Validate document format
end
step :parse_content do
# Extract content from document
end
step :request_approval do
# Wait for human approval
wait_for_approval("document_approval",
prompt: "Please review the extracted document data"
)
end
decision :check_approval do
# Route based on approval response
end
step :transform_data do
# Transform approved data
end
step :generate_report do
# Generate final report
end
step :handle_rejection do
# Handle rejection case
end
end
end- WorkflowLive: Dashboard showing all workflow executions
- DocumentLive: Form to create new document workflows
- ApprovalLive: Queue for pending human approvals
- WorkflowDetailLive: Detailed view of a single workflow
Durable creates these tables in the durable schema:
durable.workflow_executions- Workflow instancesdurable.step_executions- Step execution historydurable.pending_inputs- Human input requests
mix compilemix testmix format