aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-12-02 05:53:29 +0300
committerGitHub <noreply@github.com>2020-12-02 05:53:29 +0300
commit4c0a0e96b9a13f59785bde3e36f55f03830d58e1 (patch)
treed44eaaca96c48c1635168c938833c156779fd2ee
parent83393fd06f2a61006a28ebb45524bdd39fdfb6c1 (diff)
downloadmongo-cronjob-4c0a0e96b9a13f59785bde3e36f55f03830d58e1.tar.gz
docs: create initial README
-rw-r--r--README.md26
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!'
+ }
+});
+```