-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.js
41 lines (35 loc) · 840 Bytes
/
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
'use strict';
var CronJob = require('cron').CronJob;
var services = require('./services');
console.log('Initializing cron ...');
var users = [
'kpihus', 'ostakatel', 'noarootsi'
];
var execute = function(user){
services.getData(user, function(data){
var pellets = data.pellets;
services.writeToDb(data, user, function(err, res){
if(err){
console.log(err);
}
});
services.writePellets(pellets.current, user, function(err, res){
if(err){
console.log(err);
}
});
services.writePellets(pellets.previous, user, function(err, res){
if(err){
console.log(err);
}
})
});
}
new CronJob('1 * * * * *', function(){
console.log('Fetch data...');
for(var i=0; i<users.length; i++){
var user = users[i];
console.log('... for user', user);
execute(user);
}
}, null, true, "Europe/Tallinn");