-
Notifications
You must be signed in to change notification settings - Fork 2
/
chrone.js
62 lines (55 loc) · 1.87 KB
/
chrone.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
/* eslint camelcase:off */
require('dotenv').config();
const schedule = require('node-schedule');
const debug = require('debug')('dhis2-automatic-importations');
// calling file exten
const amoxycilline_min = require('./amoxycilline_min');
const completude_fosa = require('./completude_fosa');
const completude_pcima = require('./completude_pcima');
const completude_cs = require('./completude_cs');
const completude_hgr = require('./completude_hgr');
const completude_survepi = require('./completude_survepi');
const exhaustivite_nut = require('./exhaustivite_nut');
const exhaustivite_CS_HGR = require('./exhaustivite_CS_HGR');
const exhaustivite_all = require('./exhaustivite_all');
// const exhaustivite_med = require('./exhaustivite_med');
const codesa = require('./codesa');
const score_80 = require('./score_80');
const auth = {
user: process.env.DHIS2_USER,
pass: process.env.DHIS2_PASSWORD,
};
// Schedule execution
const rule = new schedule.RecurrenceRule();
// rule.dayOfWeek = [0, new schedule.Range(4, 6)];
rule.hour = 00;
rule.minute = 30;
function ExecuteAndCatchErrors() {
debug('Starting ExecuteAndCatchErrors()');
try {
completude_fosa.postData(auth);
completude_pcima.postData(auth);
completude_cs.postData(auth);
completude_hgr.postData(auth);
completude_survepi.postData(auth);
amoxycilline_min.postData(auth);
codesa.postData(auth);
exhaustivite_nut.postData(auth);
exhaustivite_CS_HGR.postData(auth);
exhaustivite_all.postData(auth);
score_80.postData(auth);
} catch (error) {
debug('A global error occurred.');
debug(error);
}
}
debug('Starting script');
debug(`Next run of rule at : ${rule.nextInvocationDate().toLocaleString()}`);
// Using function
schedule.scheduleJob(rule, () => {
debug('Starting jobs...');
ExecuteAndCatchErrors();
});
if (process.env.SET_IMMEDIATE_EXECUTION) {
ExecuteAndCatchErrors();
}