-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (38 loc) · 1.48 KB
/
index.js
File metadata and controls
48 lines (38 loc) · 1.48 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
const log = require('clean-log');
const getPipelineExecutionDetails = require('./functions/getPipelineExecutionDetails');
const getPipelineExecutionTimes = require('./functions/getPipelineExecutionTimes');
const sendNotification = require('./functions/sendNotification');
exports.handler = async (event, context, callback) => {
log.info(event);
let pipeline = {
name: event.detail['pipeline'],
executionId: event.detail['execution-id'],
state: event.detail['state'],
details: {},
time: {}
};
try {
pipeline.details = await getPipelineExecutionDetails(pipeline.name,pipeline.executionId)
} catch(err) {
log.error(`Unable to getPipelineExecutionDetails for ${pipeline.name} ${pipeline.executionId}`);
log.error(JSON.stringify(err,null,2));
return callback(err);
}
try {
pipeline.time = await getPipelineExecutionTimes(pipeline.name,pipeline.executionId)
} catch(err) {
log.error(`Unable to getPipelineExecutionTimes for ${pipeline.name} ${pipeline.executionId}`);
log.error(JSON.stringify(err,null,2));
return callback(err);
}
log.debug(`Sending notification with:`);
log.debug(pipeline);
try {
await sendNotification(pipeline);
} catch(err) {
log.error(`Unable to sendNotification for ${JSON.stringify(pipeline, null, 2)}`);
log.error(JSON.stringify(err,null,2));
return callback(err);
}
return callback(null);
};