From 4c0a0e96b9a13f59785bde3e36f55f03830d58e1 Mon Sep 17 00:00:00 2001 From: Eugene Sokolov Date: Wed, 2 Dec 2020 05:53:29 +0300 Subject: docs: create initial README --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 README.md (limited to 'README.md') 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!' + } +}); +``` -- cgit v1.2.3