Guides

Long-Running Processes


Long-running processes are workflows that execute over extended time periods — from hours to days to weeks — while maintaining full reliability and consistency. Orcher's durable timers let you sleep for days without consuming resources, pause for human approvals with automatic timeout and escalation, schedule future actions at precise intervals, and maintain workflow state across restarts and failures. These patterns are ideal whenever you need to wait for external events (human approvals, webhook callbacks, partner responses), schedule future actions (send a reminder in 24 hours, expire a trial in 7 days), implement timeouts (wait for payment confirmation with a 30-minute deadline), coordinate multi-day processes (order fulfillment, employee onboarding, loan approval), or handle recurring tasks (daily reports, weekly cleanups, monthly billing). Because sleeping workflows consume almost no resources, you can run thousands of concurrent long-running workflows with minimal overhead.

Trial Onboarding Workflowspans 14 days
T+0
Create accountProvision resources
T+0
Send welcome emailOnboarding guide
💤sleep(24 hours)zero resources
T+1d
Check engagementQuery usage metrics
💤sleep(6 days)zero resources
T+7d
Send midpoint emailTips & best practices
⏳wait_for_event("upgrade") · timeout 7d
T+14d
Trial expiredUpgraded? → extend : → downgrade

Durable Timers

Durable timers let your workflow sleep for extended periods — hours, days, or even weeks — without consuming any resources. The timer is persisted to the journal, so it survives server restarts, deployments, and failures. When the timer fires, the workflow resumes exactly where it left off.

1
use orcher::prelude::*;
2
use anyhow::Result;
3
use std::time::Duration;
4
use serde::{Deserialize, Serialize};
5
6
#[derive(Debug, Clone, Serialize, Deserialize)]
7
struct ReminderInput {
8
user_id: String,
9
message: String,
10
delay_hours: u64,
11
}
12
13
#[derive(Debug, Clone, Serialize, Deserialize)]
14
struct ReminderResult {
15
user_id: String,
16
sent: bool,
17
sent_at: String,
18
}
19
20
#[task]
21
async fn send_email_reminder(input: ReminderInput) -> Result<()> {
22
// Send the email reminder
23
Ok(())
24
}
25
26
#[task]
27
async fn send_reminder(message: String) -> Result<()> {
28
// Send a reminder message
29
Ok(())
30
}
31
32
// Send a reminder after a delay
33
#[workflow(name = "delayed_reminder", version = "1.0.0")]
34
pub async fn delayed_reminder(
35
ctx: WorkflowContext,
36
input: ReminderInput,
37
) -> Result<ReminderResult> {
38
println!("Reminder scheduled for {} in {} hours",
39
input.user_id, input.delay_hours);
40
41
// Sleep for the specified duration (durable - survives restarts)
42
ctx.sleep(Duration::from_secs(input.delay_hours * 3600)).await?;
43
44
println!("Timer fired - sending reminder to {}", input.user_id);
45
46
// Send the reminder
47
ctx.execute_task(send_email_reminder, input.clone()).await?;
48
49
Ok(ReminderResult {
50
user_id: input.user_id,
51
sent: true,
52
sent_at: chrono::Utc::now().to_rfc3339(),
53
})
54
}
55
56
// Multiple reminders at different intervals
57
#[workflow(name = "multi_reminder", version = "1.0.0")]
58
pub async fn multi_reminder(
59
ctx: WorkflowContext,
60
user_id: String,
61
) -> Result<()> {
62
// Send reminder after 1 day
63
ctx.sleep(Duration::from_secs(86400)).await?;
64
ctx.execute_task(send_reminder, "Day 1 reminder".to_string()).await?;
65
66
// Send reminder after 3 days (additional 2 days)
67
ctx.sleep(Duration::from_secs(172800)).await?;
68
ctx.execute_task(send_reminder, "Day 3 reminder".to_string()).await?;
69
70
// Send reminder after 7 days (additional 4 days)
71
ctx.sleep(Duration::from_secs(345600)).await?;
72
ctx.execute_task(send_reminder, "Day 7 reminder".to_string()).await?;
73
74
println!("All reminders sent for user {}", user_id);
75
Ok(())
76
}

Next Steps