blob: f7a6490bb0cfbce228b27e996d4b150005c44478 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# mongo-cronjob
Cron-based job scheduler which persists events to MongoDB
## Usage example
```js
// Define schema for event context and wrap it into a model
const contextSchema = new Schema({ message: String });
const EventModel = model('Event', contextSchema);
// Initialize scheduler
const scheduler = new Scheduler(EventModel);
scheduler.registerHandler('test', async event => {
// Your complicated async logic goes here instead
const { message } = event.context;
event.log(message);
});
EventModel.create({
type: 'test', // Matches handler type
schedule: '*/30 * * * * *', // Every 30 seconds
context: {
message: 'Hello, world!'
}
});
```
|