CRON Scheduling Made Simple with QueueSaaS
Learn how to create reliable recurring tasks using CRON expressions with QueueSaaS. Schedule daily reports, hourly health checks, and complex recurring workflows.
CRON Scheduling Made Simple with QueueSaaS
CRON scheduling is one of the most powerful features of QueueSaaS, allowing you to create reliable, recurring tasks without managing your own scheduler infrastructure. Whether you need daily reports, hourly health checks, or complex recurring workflows, QueueSaaS handles the scheduling, execution, and retry logic for you.
Why Use CRON Scheduling?
Traditional approaches to recurring tasks often involve:
- Managing cron servers
- Handling timezone complexities
- Dealing with missed executions
- Implementing retry logic
- Monitoring execution status
QueueSaaS eliminates all of this by providing a fully managed CRON scheduling service that:
- ✅ Executes tasks reliably on schedule
- ✅ Supports any timezone
- ✅ Handles retries automatically if execution fails
- ✅ Tracks execution history
- ✅ Allows pause/resume without losing schedule
Getting Started
Basic CRON Schedule
import { Client } from '@anlyonhq/scheduler';
const client = new Client({
apiKey: process.env.ANLYON_API_KEY!,
});
// Create a daily schedule at 9 AM
await client.schedules.create({
name: 'Daily Report',
cronExpression: '0 9 * * *', // 9:00 AM every day
timezone: 'America/New_York',
url: 'https://api.example.com/report',
method: 'POST',
body: { type: 'daily_report' },
});
Using the Fluent Builder
The SDK provides a fluent builder API for common scheduling patterns:
// Hourly schedule
await client.schedules
.createSchedule()
.name('Hourly Health Check')
.hourly()
.to('https://api.example.com/health-check')
.body({ check: 'system' })
.create();
// Daily schedule
await client.schedules
.createSchedule()
.name('Daily Backup')
.daily()
.at('02:00') // 2 AM
.to('https://api.example.com/backup')
.create();
// Weekly schedule
await client.schedules
.createSchedule()
.name('Weekly Summary')
.weekly()
.on('Monday')
.at('09:00')
.to('https://api.example.com/weekly-summary')
.create();
Common CRON Patterns
Every Minute
cronExpression: '* * * * *'
Every Hour
cronExpression: '0 * * * *'
Every Day at 9 AM
cronExpression: '0 9 * * *'
Every Monday at 9 AM
cronExpression: '0 9 * * 1'
Every 1st of the Month at Midnight
cronExpression: '0 0 1 * *'
Every 15 Minutes
cronExpression: '*/15 * * * *'
Timezone Support
QueueSaaS supports all IANA timezone identifiers, making it easy to schedule tasks in any timezone:
// Schedule in different timezones
await client.schedules.create({
name: 'Tokyo Daily Report',
cronExpression: '0 9 * * *',
timezone: 'Asia/Tokyo', // 9 AM Tokyo time
url: 'https://api.example.com/report',
});
await client.schedules.create({
name: 'London Daily Report',
cronExpression: '0 9 * * *',
timezone: 'Europe/London', // 9 AM London time
url: 'https://api.example.com/report',
});
Managing Schedules
List All Schedules
const schedules = await client.schedules.list();
console.log(`You have ${schedules.data.length} active schedules`);
Pause and Resume
Temporarily disable a schedule without deleting it:
// Pause a schedule
await client.schedules.pause('schedule-id');
// Resume a paused schedule
await client.schedules.resume('schedule-id');
Update a Schedule
Modify an existing schedule:
await client.schedules.update('schedule-id', {
name: 'Updated Schedule Name',
cronExpression: '0 10 * * *', // Change to 10 AM
body: { type: 'updated_report' },
});
Delete a Schedule
await client.schedules.delete('schedule-id');
Real-World Examples
Daily Email Digest
await client.schedules.create({
name: 'Daily Email Digest',
cronExpression: '0 8 * * *', // 8 AM every day
timezone: 'America/New_York',
url: 'https://api.example.com/send-digest',
method: 'POST',
body: {
type: 'email_digest',
recipients: ['team@example.com'],
},
});
Weekly Database Cleanup
await client.schedules.create({
name: 'Weekly Database Cleanup',
cronExpression: '0 2 * * 0', // 2 AM every Sunday
timezone: 'UTC',
url: 'https://api.example.com/cleanup',
method: 'POST',
body: {
type: 'database_cleanup',
retentionDays: 90,
},
});
Hourly Metrics Collection
await client.schedules.create({
name: 'Hourly Metrics',
cronExpression: '0 * * * *', // Every hour
url: 'https://api.example.com/collect-metrics',
method: 'POST',
body: {
type: 'metrics',
interval: 'hourly',
},
});
Best Practices
- Use descriptive names: Make it easy to identify schedules in your dashboard
- Choose appropriate timezones: Schedule tasks when they’re needed, not just in UTC
- Handle failures gracefully: Your webhook should handle errors and return appropriate status codes
- Monitor execution: Use the analytics API to track schedule execution success rates
- Test your schedules: Use the pause feature to test webhook endpoints before enabling schedules
Advanced Features
Custom Headers
Add custom headers to your scheduled requests:
await client.schedules.create({
name: 'Authenticated Schedule',
cronExpression: '0 9 * * *',
url: 'https://api.example.com/secure-endpoint',
headers: {
'Authorization': 'Bearer your-token',
'X-Custom-Header': 'value',
},
body: { data: 'value' },
});
Execution History
QueueSaaS tracks execution history for all schedules:
const schedule = await client.schedules.get('schedule-id');
console.log(`Last executed: ${schedule.data.lastExecutedAt}`);
console.log(`Next execution: ${schedule.data.nextRunAt}`);
console.log(`Status: ${schedule.data.status}`);
Troubleshooting
Schedule Not Executing
- Check if the schedule is paused
- Verify the CRON expression is correct
- Ensure the timezone is set correctly
- Check your webhook endpoint is accessible
- Review execution logs in the dashboard
Timezone Issues
Always specify timezones explicitly. If you don’t, schedules default to UTC:
// Good - explicit timezone
cronExpression: '0 9 * * *',
timezone: 'America/New_York',
// Avoid - defaults to UTC
cronExpression: '0 9 * * *',
// timezone not specified
Next Steps
- Learn about URL Groups for fan-out messaging
- Explore Dead Letter Queue management
- Check out our TypeScript SDK guide
Start scheduling your recurring tasks today with QueueSaaS! 🕐