forked from torenergy/metabase-pulses
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
39 lines (29 loc) · 1.04 KB
/
index.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
var saveQuestion = require('./questionService');
var mailQuestion = require('./mailService');
async function processPulse(pulse) {
let questionIds = pulse.questionIds
let questions = []
for (let questionId of questionIds) {
try {
const question = await saveQuestion(questionId)
questions.push(question);
} catch(e) {
console.error(e);
}
}
return mailQuestion(pulse.subject,pulse.mailTo,questions)
}
async function main() {
let args = process.argv.slice(2);
let pulsesFile = "pulses.json";
if ( args.length >= 0 ) {
pulsesFile = args[0];
}
console.log("===============SENDING PULSES===============")
const pulses = require('./'+pulsesFile)
await Promise.all(pulses.map(p => processPulse(p).catch(e => console.log(e))))
console.log("===============PULSES SENT===============")
// In case o error, for an unknow reason the node process gets stuck even tough all promises were resolved
process.exit(0)
}
main().catch(console.error);