Coming from Laravel workflows (Rust)
Laravel for Rust (laravel-rust) includes durable workflows. A #[workflow] struct's
handle method records each run.step in a store and resumes from the last recorded step.
That covers many applications. This page is for the point where you need more than a sequence
of steps, waits and sleeps on one queue. Examples are child workflows, signals and queries,
parallel steps, continue-as-new, activity heartbeats, versioning, workers in other languages,
or a runtime with its own history and UI.
Durable Workflow runs in the same application. The durable-workflow-laravel crate adds a
service provider, an injectable DurableWorkflow entry point, a durable-workflow:work
command and a test fake. Both kinds of workflow can run side by side while you move them over
one at a time.
Concepts side by side
| Laravel for Rust | Durable Workflow | Notes |
|---|---|---|
#[workflow] impl Checkout { async fn handle(self, run: &Run) } | worker.register_typed_workflow("orders.checkout", checkout) | The workflow body is replayed from the Server's history, so it must be deterministic. |
run.step("charge card", work) | ctx.activity_typed("orders.charge", input) | An activity runs on any worker polling its task queue, with its own retry policy and timeouts (ActivityOptions). |
Step::tries / Step::backoff / Step::timeout | ActivityOptions::retry_policy, start_to_close_timeout, schedule_to_close_timeout, heartbeat_timeout | Activities can heartbeat progress and resume from a checkpoint. |
run.sleep(3.days()) | ctx.sleep(Duration::from_secs(3 * 86_400)) | A durable timer kept by the Server. |
run.wait_for::<T>(token) and workflow::resume(token, value) | A signal: workflows.signal(id, "approve", value) and, in the workflow, wait_condition! on ctx.signals("approve") | Signals are addressed by workflow ID and name, not by a token. |
run.inbox_for::<T>(token) and Inbox::next | Repeated signals read with ctx.signals(name), or a message stream (ctx.message_stream(name)) | Both keep every value in arrival order. |
Wait::resume_url / webhook_url | A route in your application that calls DurableWorkflow::signal or update | You choose the URL, its authentication and its validation. |
Wait::timeout(5.days()) | wait_condition!(ctx, "approved", timeout: Duration::from_secs(5 * 86_400), ...) | Returns ConditionWaitResult::TimedOut instead of None. |
workflow::cancel(run_id) | workflows.cancel(id, Some("reason")) | Cooperative cancellation scopes are available too. |
workflow::find(run_id) / RunInfo | client.describe_workflow(id), run history and Waterline | |
OnboardUser { .. }.start().await | workflows.start("users.onboard", input).await | Starts on the configured task queue with a generated ID, unless StartOptions set them. |
workflow::fake() and assert_started | DurableWorkflow::fake(&app) and assert_workflow_started | See Test with the fake. |
cargo artisan queue:work runs the advances | cargo artisan durable-workflow:work | Workers poll the Server. Your database needs no workflow tables. |
Waiting for an approval
A Laravel workflow waits for a token and resumes from a URL:
let decision = run.wait::<Decision>();
let approve = decision.resume_url(Decision::Approved)?.to_string();
run.step("email the manager", email(approve)).await?;
let decision = decision.timeout(3.days()).await?;
In Durable Workflow the workflow waits for a signal, and an ordinary route sends it:
worker.register_typed_workflow("expenses.approve", |ctx, expense: Expense| async move {
ctx.activity_typed::<_, ()>("expenses.email_manager", expense.clone()).await?;
let signals = ctx.clone();
let outcome = wait_condition!(
ctx,
"decision",
timeout: Duration::from_secs(3 * 86_400),
move || Ok(!signals.signals("decide")?.is_empty()),
)
.await?;
Ok(outcome.is_timed_out())
});
worker.declare_workflow_signals("expenses.approve", &["decide"])?;
async fn decide(
workflows: Inject<DurableWorkflow>,
Params(id): Params<String>,
Json(decision): Json<Decision>,
) -> laravel::Result<StatusCode> {
workflows.signal(&id, "decide", decision).await?;
Ok(StatusCode::ACCEPTED)
}
Signals that arrive before the wait
ctx.wait_signal waits for a signal delivered after the wait opens. A signal can arrive
earlier, as an approval can while an earlier activity still runs. In that case wait on
ctx.signals(..) with wait_condition!, as the example above does. ctx.signals(name)
returns every signal the run has received with that name, so the condition also sees signals
delivered before the wait.
What you gain
- Child workflows with their own history, retries, parent-close policies and cancellation.
- Signals, queries and updates. Send data in, read live state out, and change state with a validated, acknowledged result.
- Parallel steps with
ctx.parallel,joinandselect, with a failure policy per group, and sagas with compensation. - Continue-as-new for long-running and looping workflows, with history-size budgets.
- Heartbeats and acknowledged checkpoints for long activities.
- Versioning with
ctx.patchedand replay tests (durable_workflow::testing) before you deploy changed workflow code. - Inbox and outbox patterns. Message streams carry ordered inbound messages, and side effects are recorded once. The inbox and outbox patterns originated in Durable Workflow (durable-workflow/workflow#309 and #311, February 2026).
- Polyglot workers. The same workflow can call activities written in PHP, Python or Rust, because payloads use one Avro value schema.
- A runtime of its own. The self-hosted Server or Durable Workflow Cloud keeps history, timers and task queues, and Waterline shows every run, its history and its failures.
Install
Add the crate to your Laravel for Rust application:
cargo add durable-workflow-laravel
# Laravel for Rust needs a newer compiler, so skip the core crate's default
# Rust 1.86 dependency pin, as the integration does.
cargo add durable-workflow --no-default-features
cargo add laravel-rust@=0.1.2 --rename laravel
Register the provider
Workflow and activity code uses types and macros from the core durable-workflow crate, so the
application depends on it as well. The integration pins one exact laravel-rust release,
because the Laravel for Rust API can change in any minor release. It needs the same minimum
Rust version as Laravel for Rust.
Register DurableWorkflowServiceProvider and add your workflows and activities in its worker
callback:
use durable_workflow_laravel::DurableWorkflowServiceProvider;
fn main() -> std::process::ExitCode {
laravel::Application::configure()
.with_providers(|providers| {
providers.add(DurableWorkflowServiceProvider::new().worker(|mut worker, _app| {
worker.register_typed_workflow("orders.checkout", |ctx, order_id: u64| async move {
ctx.activity_typed::<_, String>("orders.charge", order_id).await
});
worker.register_typed_activity("orders.charge", |_ctx, order_id: u64| async move {
Ok(format!("charged order {order_id}"))
});
Ok(worker)
}));
})
.run()
}
The worker callback receives the durable_workflow::Worker that durable-workflow:work runs,
so it can register workflows, activities, queries and updates and set any worker option. It
also receives the Application. Activities run outside Laravel's request context. An activity
that needs a Laravel service runs its body in app.scope(..).
Configure the connection with DURABLE_WORKFLOW_RUNTIME_URL, DURABLE_WORKFLOW_NAMESPACE,
DURABLE_WORKFLOW_TASK_QUEUE and the credential variables DURABLE_WORKFLOW_TOKEN,
DURABLE_WORKFLOW_CLIENT_TOKEN and DURABLE_WORKFLOW_WORKER_TOKEN. The settings form the
DurableWorkflowConfig section. The application's client never receives the worker token, so
a web process can run without the worker credential. The
crate README
lists every setting and its default.
Run a worker
cargo artisan durable-workflow:work
cargo artisan durable-workflow:work --queue orders --poll-timeout 10 --worker-id web-1
The command builds a worker with the worker credential, runs the worker callbacks and polls
the Server. Ctrl+C or SIGTERM stops the worker after its current tasks. The command refuses to
start without registered workflows or activities, or with a handler name registered twice.
Start and interact with workflows
Handlers take Inject<DurableWorkflow>:
use durable_workflow_laravel::{DurableWorkflow, StartOptions};
use laravel::prelude::*;
async fn checkout(workflows: Inject<DurableWorkflow>, Params(order_id): Params<u64>) -> laravel::Result<String> {
let workflow = workflows
.start_with("orders.checkout", order_id, StartOptions::new().id(format!("order-{order_id}")))
.await?;
Ok(workflow.id().to_owned())
}
async fn approve(workflows: Inject<DurableWorkflow>, Params(id): Params<String>) -> laravel::Result<()> {
workflows.signal(&id, "approve", ()).await?;
let status: String = workflows.query(&id, "status", ()).await?;
let note: String = workflows.update(&id, "note", "gift wrap").await?;
Ok(())
}
async fn receipt(workflows: Inject<DurableWorkflow>, Params(id): Params<String>) -> laravel::Result<String> {
let receipt: String = workflows.workflow(id).result().await?;
Ok(receipt)
}
start uses the configured task queue and a generated workflow ID such as
orders-checkout-<uuid>. start_with takes StartOptions for the ID, the task queue and
timeouts. Both return a WorkflowInstance, which signals, queries, updates, cancels and waits
for the typed result with result::<T>(). DurableWorkflow::workflow(id) returns a
WorkflowInstance for an existing workflow ID. Waiting for a result works both on the instance
from start and on one from workflow(id). DurableWorkflow::client() returns the SDK client
for everything else.
Outside a handler, such as in a job or a scheduled task, resolve the same entry point with
durable_workflow_laravel::workflows():
durable_workflow_laravel::workflows()
.await?
.signal("order-42", "approve", ())
.await?;
Test with the fake
DurableWorkflow::fake(&app) swaps a fake into the container and returns it. Swap the fake in
before the requests or commands that use the service:
use durable_workflow_laravel::DurableWorkflow;
use laravel::testing::prelude::*;
use serde_json::json;
#[laravel::test]
async fn checkout_starts_the_workflow(app: Application) {
let workflows = DurableWorkflow::fake(&app);
workflows.set_query_result("order-42", "status", "approved");
app.post("/api/orders/42/checkout").await.assert_ok();
workflows
.assert_workflow_started_with("orders.checkout", 42)
.assert_workflow_started_where("orders.checkout", |started| started.workflow_id == "order-42");
}
The fake records starts, signals, queries, updates, result waits and cancellations. It answers
queries, updates and results with values set by set_query_result, set_update_result and
set_workflow_result. Its assertions are assert_workflow_started,
assert_workflow_started_with, assert_workflow_started_where, assert_workflow_started_times,
assert_workflow_not_started, assert_nothing_started, assert_signal_sent,
assert_signal_sent_with, assert_signal_not_sent, assert_query_requested,
assert_query_requested_with, assert_update_requested, assert_update_requested_with,
assert_result_requested and assert_cancel_requested. Each assertion returns the fake, so
assertions chain.
Test workflow code itself with durable_workflow::testing::WorkflowEnvironment, which runs
workflows and activities without a Server and replays recorded histories. See
Offline tests and replay.
Move a workflow over
- Register the Durable Workflow version under a new workflow type and route new starts to it.
- Let the Laravel runs that are in progress finish. Both kinds run side by side.
- Replace
run.stepclosures with activities,run.sleepwithctx.sleep, and tokens and resume URLs with signals and your own routes. - Move the tests from
workflow::fake()toDurableWorkflow::fake(&app).