evercron
v1.0.1
Published
MongoDB-persistent job scheduler
Readme
EverCron – Persistent MongoDB Job Scheduler
Persistent cron jobs for Node.js with MongoDB storage.
Survives server restarts and supports flexible scheduling.
🚀 Quick Start
1. Install
npm install evercron mongodb2. Basic Usage
const { MongoClient } = require('mongodb');
const EverCron = require('evercron');
(async () => {
// 1. Connect to MongoDB
const client = await MongoClient.connect('mongodb://localhost:27017');
const jobs = client.db('myapp').collection('cronJobs');
// 2. Create scheduler
const scheduler = new EverCron(jobs);
// 3. Schedule jobs
await scheduler.schedule(
'nightly-backup',
'daily at 02:00',
backupDatabase,
{ timezone: 'Asia/Kolkata' }
);
})();🕒 Schedule Formats
| Type | Example | Description |
|----------|---------------------|---------------------|
| Interval | 'every 30 minutes' | Recurring duration |
| Daily | 'daily at 15:30' | Specific time daily |
| Cron | '0 * * * *' | Standard cron syntax|
🔧 API Reference
schedule(name, schedule, taskFn, options)
Schedule a new job.
await scheduler.schedule(
'weekly-report',
'0 9 * * 1', // Every Monday at 9 AM
generateReport,
{
maxRetries: 3,
timezone: 'America/Chicago'
}
);cancel(name)
Cancel a scheduled job.
await scheduler.cancel('obsolete-job');restore()
Restore scheduled jobs after a server restart.
await scheduler.restore();🧪 Testing in Development
Manually Trigger a Job
await scheduler.schedule(
'test-job',
'every 1 minute',
testTask,
{ timezone: 'UTC' }
);📄 List All Jobs
const jobs = await jobsCollection.find().toArray();
```---
## 🧪 How to Test Jobs in Development?
### Manually Trigger a Job
```js
await scheduler.schedule(
'test-job',
'every 1 minute',
testTask,
{ timezone: 'UTC' }
);📋 How to List All Jobs?
const jobs = await jobsCollection.find().toArray();