diff options
-rw-r--r-- | README.md | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..f7a6490 --- /dev/null +++ b/README.md @@ -0,0 +1,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!' + } +}); +``` |