Loading...
Loading...
Schedule future work in Serverpod — FutureCall, callWithDelay, callAtTime, recurring tasks, cancellation. Use when scheduling one-off or recurring tasks.
npx skill4agent add serverpod/serverpod serverpod-schedulingclass ExampleFutureCall extends FutureCall {
Future<void> doWork(Session session) async {
// Work here.
}
Future<void> doOtherWork(Session session, MyModel data) async {
// Work with data.
}
}serverpod generatepod.futureCalls// Delay
await pod.futureCalls
.callWithDelay(const Duration(hours: 1))
.example.doWork();
// At specific time (UTC)
await pod.futureCalls
.callAtTime(DateTime.utc(2026, 1, 1))
.example.doOtherWork(myModel);
// With identifier (for cancellation)
await pod.futureCalls
.callWithDelay(const Duration(hours: 1), identifier: 'my-job-id')
.example.doWork();
// Recurring task from `Duration` interval with an optional start time
await pod.futureCalls
.callRecurring()
.every(const Duration(hours: 1), start: DateTime.now())
.example.doWork();
// Recurring task from `cron` expression
await pod.futureCalls
.callRecurring()
.cron("0 * * * *")
.example.doWork();
await pod.futureCalls.cancel('my-job-id'); // Cancels all with that identifierfutureCallExecutionEnabled: true # SERVERPOD_FUTURE_CALL_EXECUTION_ENABLED
futureCall:
concurrencyLimit: 5 # SERVERPOD_FUTURE_CALL_CONCURRENCY_LIMIT (default 1, <1 maps to unlimited and is not recommended)
scanInterval: 2000 # SERVERPOD_FUTURE_CALL_SCAN_INTERVAL (ms, default 5000)