blob: 4356a70cec67b3330f97decd59276e24ac413f60 (
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
27
28
29
30
|
# mongo-cronjob
Cron-based job scheduler which persists events to MongoDB
## Usage example
```js
const mongoose = require('mongoose');
const { Client, Scheduler } = require('mongo-cronjob');
// Initialize client with existing connection
const client = new Client(mongoose.connection);
const EventModel = client.Event;
const LogModel = client.Log;
// 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!'
}
});
```
|