Skip to content

Commit

Permalink
schedule every hour and daily digest operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinav Sinha committed May 12, 2021
1 parent ce4874b commit 6eb455a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ const SERVICE_PROVIDER = 'Gmail';
const RECIPIENT = '[email protected],[email protected],[email protected]';
```

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;
```

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/configs/schedulerConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const SCHEDULE = '15 * * * *';
const SCHEDULE = '0 15 * * * *';
const DATE_RANGE = 7;
const DATE_FORMAT = 'DD-MM-YYYY';

Expand Down

0 comments on commit 6eb455a

Please sign in to comment.