-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.js
79 lines (72 loc) · 2.43 KB
/
cron.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var cron = require('cron');
var axios = require('axios');
console.log('ad-cronjobs is running');
// checks out coworkers who forgot to check out manually
var flexGlobalCheckout = new cron.CronJob({
cronTime: process.env.FLEX_CHECKOUT_TIME || '2 0 * * *',
onTick: function() {
now = new Date();
console.log(now + ': job flexGlobalCheckout ticked');
if(process.env.FLEX_CHECKOUT_URL) {
axios.get(process.env.FLEX_CHECKOUT_URL)
.then(function (response) {
console.log("job flexGlobalCheckout - HTTP Request made on " + process.env.FLEX_CHECKOUT_URL);
})
.catch(function (err) {
console.log("job flexGlobalCheckout - Error: " + err);
});
}
else
{
console.log("job flexGlobalCheckout - Error: env variable FLEX_CHECKOUT_URL not set");
}
},
start: true,
timeZone: 'Europe/Paris'
});
// just in case the first script didn't run smooth we run flexGlobalCheckout again a few minutes later
var flexGlobalCheckout2 = new cron.CronJob({
cronTime: process.env.FLEX_CHECKOUT_TIME2 || '5 0 * * *',
onTick: function() {
now = new Date();
console.log(now + ': job flexGlobalCheckout2 ticked');
if(process.env.FLEX_CHECKOUT_URL) {
axios.get(process.env.FLEX_CHECKOUT_URL)
.then(function (response) {
console.log("job flexGlobalCheckout2 - HTTP Request made on " + process.env.FLEX_CHECKOUT_URL);
})
.catch(function (err) {
console.log("job flexGlobalCheckout2 - Error: " + err);
});
}
else
{
console.log("job flexGlobalCheckout2 - Error: env variable FLEX_CHECKOUT_URL not set");
}
},
start: true,
timeZone: 'Europe/Paris'
});
// same thing on staging
var flexGlobalCheckoutStaging = new cron.CronJob({
cronTime: process.env.STAGING_FLEX_CHECKOUT_TIME || '2 0 * * *',
onTick: function() {
now = new Date();
console.log(now + ': job flexGlobalCheckoutStaging ticked');
if(process.env.STAGING_FLEX_CHECKOUT_URL) {
axios.get(process.env.STAGING_FLEX_CHECKOUT_URL)
.then(function (response) {
console.log("job flexGlobalCheckoutStaging - HTTP Request made on " + process.env.STAGING_FLEX_CHECKOUT_URL);
})
.catch(function (err) {
console.log("job flexGlobalCheckoutStaging - Error: " + err);
});
}
else
{
console.log("job flexGlobalCheckoutStaging - Error: env variable STAGING_FLEX_CHECKOUT_URL not set");
}
},
start: true,
timeZone: 'Europe/Paris'
});