Scheduled actions
What Are Scheduled Actions?
Scheduled actions are repeating tasks that your app defines to run at regular intervals. These could include syncing data, sending reminders, or logging stats.
You define these inside the scheduledActions
array of your index.js file.
Basic Syntax
scheduledActions: [
{
name: "daily_sync", // Must match the name used in scheduleAppJobs
run: async (r, args) => {
// logic here
},
interval: 43200 // Run every 12 hours (in seconds)
}
]
Example
const COUNT_KEY = "run-count";
scheduledActions: [
{
name: "log_stats",
interval: 43200,
run: async (r, args) => {
let count = await r.kv.getAppValue(COUNT_KEY);
count = (count || 0) + 1;
if (count >= 10) {
await r.scheduler.deleteScheduledJob("log_stats");
return;
}
await r.kv.setAppValue({ key: COUNT_KEY, value: count });
r.log.info(`Stats logged ${count} times.`);
}
}
]
Notes
- run receives
r
(Rocketlane SDK context) andargs
(event-specific data). - You can persist run state using
r.kv
. - Use interval to control how often the job runs (minimum supported interval depends on platform constraints).
Updated about 1 month ago
What’s Next