Scheduler
Scheduler → Function
Run a one-off task at a specific time (e.g. send email in 1 hour).
The Pattern
Scheduler Function
Why this pattern?
- One-time execution: No recurring cron — runs once at the given time
- Timezone support: Schedule in any timezone
- Payload: Pass context (user, order, type) so the function knows what to do
- Use cases: Reminders, delayed notifications, "cancel if no payment" flows
Example implementation
// Schedule a one-off task (e.g. "send reminder in 1 hour")
const inOneHour = new Date(Date.now() + 60 * 60 * 1000).toISOString()
await fetch('https://api.rocketstack.dev/schedules', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'reminder',
runAt: inOneHour,
deliveryTarget: {
type: 'function',
functionId: 'fn_send_reminder'
},
payloadTemplate: {
userId: 'usr_123',
type: 'payment_reminder',
orderId: 'ord_456'
}
})
});
// Your Function runs once at the scheduled time
// fn_send_reminder
export default async function handler(event) {
const { userId, type, orderId } = event.payload;
if (type === 'payment_reminder') {
const user = await getUser(userId);
await sendEmail(user.email, {
subject: 'Complete your purchase',
body: `Your order ${orderId} is waiting. Complete payment within 24h.`
});
}
return { sent: true };
} Free tier available
Ready to start building?
Create your free account and integrate infrastructure primitives in minutes.