-
Notifications
You must be signed in to change notification settings - Fork 0
/
runkit-example.js
34 lines (30 loc) · 914 Bytes
/
runkit-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* This is a how to use live example
*/
// Import the library
const { CronJob } = require('schedule-jobs-with-cron');
// Let's define an end date in one minute, we don't want this demo to run forever
const now = new Date();
const endInMinutes = 1;
const endDate = new Date(now.getTime() + endInMinutes * 60000);
// Define and schedule a new job
const job1 = new CronJob(
'A test Job 1',
(triggerTime, log) => {
log('info', `Hello from inside the job, it was triggered at: ${triggerTime}`);
/***
Add code that does some work here
***/
},
// A cron schedule that runs every minute
'* * * * *',
{
endDate: endDate,
},
);
// Await for the job.
// Non-blocking; other functions can run in the meantime,
// but any further lines in this one won't start until the promise resolves.
await job1.getPromise();
console.log('done');
/**** watch for console log output below ****/