-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
58 lines (42 loc) · 1.12 KB
/
app.js
File metadata and controls
58 lines (42 loc) · 1.12 KB
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
const getData = require('./getData');
const applogger = require('./applogger');
const config = require('./config');
const request = require('request');
const cron = require('node-cron');
cron.schedule('0 8,17 * * *', () => {
ejecutar();
var data = 'agendado para ejecucion';
applogger(data);
}, {
scheduled: true,
timezone: "America/Asuncion"
});
var ejecutar = async function() {
request.get({
method: 'GET',
uri: config.get('AGENCIAS_LISTA_URL'),
headers: {'content-type': 'application/json'}
}, async function (error, res, datos) {
if (error) {
console.error(error);
applogger(`hubo un error al invocar lista agencias: ${error}`);
return;
}
applogger(`lista agencias statusCode: ${res.statusCode}`);
let listaAgencias = JSON.parse(res.body);
if (res.statusCode == 200) {
try {
await getData(listaAgencias.body);
var data = 'proceso finalizado';
applogger(data);
} catch (error) {
var data = 'completado con error \n';
data += 'error: ' + error;
applogger(data);
}
} else {
var data = 'no se pudo procesar';
applogger(data);
}
});
}