From 6eb455ae79ba7a8ada3c7d60e2cd813288e1ba40 Mon Sep 17 00:00:00 2001 From: Abhinav Sinha Date: Wed, 12 May 2021 12:25:57 +0530 Subject: [PATCH] schedule every hour and daily digest operations --- README.md | 4 ++-- package.json | 3 ++- src/app.js | 4 ++-- src/configs/schedulerConfig.js | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index edd7e7e..1f98f71 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,10 @@ const SERVICE_PROVIDER = 'Gmail'; const RECIPIENT = 'mail1@gmail.com,mail2@gmail.com,mail3@gmail.com'; ``` -Finally, you can also alter the date range with which the application will fetch vaccination slots by customising **DATE_RANGE** value in [`src/configs/schedulerConfig.js`](https://github.com/sinhadotabhinav/covid-19-vaccine-alerts-cowin/blob/master/src/configs/schedulerConfig.js) file. By default it is set to **7** but, you can change it to 10 or 15 for example, based on your need. The config file also allows changes in the periodic schedule with which the application runs. By default, **SCHEDULE** value depicts a cron schedule **every hour at minute 15**. To alter this schedule, you need to be familiar with the [cron scheduler](https://linuxhint.com/cron_jobs_complete_beginners_tutorial/#:~:text=The%20scheduled%20commands%20and%20scripts,Task%20Scheduler%20in%20Windows%20OS). I use [Crontab Guru](https://crontab.guru) website to test my cron schedules. +Finally, you can also alter the date range with which the application will fetch vaccination slots by customising **DATE_RANGE** value in [`src/configs/schedulerConfig.js`](https://github.com/sinhadotabhinav/covid-19-vaccine-alerts-cowin/blob/master/src/configs/schedulerConfig.js) file. By default it is set to **7** but, you can change it to 10 or 15 for example, based on your need. The config file also allows changes in the periodic schedule with which the application runs. By default, **SCHEDULE** value depicts a cron schedule **every hour at minute 15 and second 0**. To alter this schedule, you need to be familiar with the [cron scheduler](https://linuxhint.com/cron_jobs_complete_beginners_tutorial/#:~:text=The%20scheduled%20commands%20and%20scripts,Task%20Scheduler%20in%20Windows%20OS). I use [Crontab Guru](https://crontab.guru) website to test my cron schedules. ``` -const SCHEDULE = '15 * * * *'; +const SCHEDULE = '0 15 * * * *'; const DATE_RANGE = 7; ``` diff --git a/package.json b/package.json index 18271bf..fb1a22c 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "covid-19-vaccine-alerts-cowin", - "version": "1.0.1", + "version": "1.0.2", "description": "This is an alerting application that sends email notifications to beneficiaries in India using COWIN platform for vaccine availability", "main": "src/app.js", "scripts": { + "start": "node src/app", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "asinha093@gmail.com", diff --git a/src/app.js b/src/app.js index 171759f..b8c2052 100644 --- a/src/app.js +++ b/src/app.js @@ -152,8 +152,8 @@ async function sendEmailAlert(slotsArray) { async function resetDailyCounter() { const interval = parser.parseExpression(schedulerConfig.SCHEDULE); - let difference = moment(new Date(interval.next().toString())).diff(moment(), 'days', true); - if (difference.toFixed() > 0) { + let lastRun = moment().date() == moment(new Date(interval.next().toString())).date() ? false : true; + if (Boolean(lastRun)) { await dailyDigest.prepareReport(); runCounter = 0; } diff --git a/src/configs/schedulerConfig.js b/src/configs/schedulerConfig.js index e9cfbfa..9ec4012 100644 --- a/src/configs/schedulerConfig.js +++ b/src/configs/schedulerConfig.js @@ -1,4 +1,4 @@ -const SCHEDULE = '15 * * * *'; +const SCHEDULE = '0 15 * * * *'; const DATE_RANGE = 7; const DATE_FORMAT = 'DD-MM-YYYY';