Composable, resilient long-running tasks with automatic checkpoint recovery, structured concurrency, and dependency injection. Production-ready for AI agents, workflows, and complex async operations.
Cloudflare Durable Objects can evict your code after ~144 seconds of inactivity. For long-running operations (like AI agent loops), a single eviction mid-task breaks your workflow.
ironalarm solves this with a lightweight, userspace implementation that persists task state and uses a 30-second safety alarm net—if evicted, the task automatically retries and resumes from checkpoints.
Composable effects with dependency injection and structured concurrency
Exponential backoff retry with Schedule.exponential for resilient execution
Non-blocking concurrent task processing with configurable limits
Hash-based routing for horizontal scaling across multiple DO instances
Type-safe error handling with Data.TaggedError
Built-in observability with Effect.log* for production monitoring
import { ReliableScheduler, SchedulerService } from 'ironalarm';
import { Effect } from 'effect';
export class MyDO {
private scheduler: ReliableScheduler;
constructor(state: DurableObjectState, env: any) {
// Initialize with DO storage + concurrency limits
this.scheduler = new ReliableScheduler(state.storage, {
maxConcurrentTasks: 10
});
// Register Effect-powered task handler with dependency injection
this.scheduler.register('my-task', (taskId, params) => {
return Effect.gen(function* () {
const svc = yield* SchedulerService;
const started = yield* svc.getCheckpoint(taskId, 'started');
if (!started) {
yield* Effect.promise(() => doWork(params));
yield* svc.checkpoint(taskId, 'started', true);
}
yield* svc.completeTask(taskId);
yield* Effect.log('Task completed successfully');
});
});
}
async alarm() {
// Process due tasks with structured concurrency
await Effect.runPromise(this.scheduler.alarm());
}
}
All methods available on the ReliableScheduler class.
new ReliableScheduler(storage: DurableObjectStorage) Creates a new scheduler instance with the provided Durable Object storage.
register (taskName: string, handler: Function) Register a named task handler. The handler receives the scheduler, taskId, and params.
runNow (taskId: string, taskName: string, params?: any) Start a task immediately with eviction safety. Sets a 30s safety alarm for automatic retry.
schedule (at: number, taskId: string, taskName: string, params?: any) Schedule a task to run at a future time (Unix timestamp).
checkpoint (taskId: string, key: string, value: any) Save progress for a task. Use this to mark completion of expensive operations.
getCheckpoint (taskId: string, key: string) Retrieve saved progress for a task. Returns undefined if not found.
completeTask (taskId: string) Mark a task as complete and clean up its state.
alarm () Call this from your Durable Object's alarm handler to process scheduled tasks.
Start a simulated long-running task and watch the checkpoint system in action.
Simulates a long-running agent task with checkpoints: research → analysis → synthesis → writeup
No tasks yet. Start one above to see the scheduler in action!