Skip to content

Commit 2c02568

Browse files
mads-hartmannroboquat
authored andcommitted
Avoid using process.exit as we need to flush telemetry
1 parent 7abdeab commit 2c02568

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

.werft/build.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ Tracing.initialize()
2929
})
3030

3131
if (context.Repository.ref === "refs/heads/main") {
32-
reportBuildFailureInSlack(context, err, () => process.exit(1));
32+
reportBuildFailureInSlack(context, err).catch((error: Error) => {
33+
console.error("Failed to send message to Slack", error)
34+
});
3335
} else {
3436
console.log('Error', err)
35-
// Explicitly not using process.exit as we need to flush tracing, see tracing.js
36-
process.exitCode = 1
3737
}
38+
39+
// Explicitly not using process.exit as we need to flush tracing, see tracing.js
40+
process.exitCode = 1
3841
})
3942
.finally(() => {
4043
werft.phase("Stop kubectl port forwards", "Stopping kubectl port forwards")

.werft/util/slack.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as https from 'https';
22

3-
export function reportBuildFailureInSlack(context, err, onErr) {
3+
export function reportBuildFailureInSlack(context, err: Error): Promise<void> {
44
const repo = context.Repository.host + "/" + context.Repository.owner + "/" + context.Repository.repo;
55
const data = JSON.stringify({
66
"blocks": [
@@ -31,17 +31,19 @@ export function reportBuildFailureInSlack(context, err, onErr) {
3131
}
3232
]
3333
});
34-
const req = https.request({
35-
hostname: "hooks.slack.com",
36-
port: 443,
37-
path: process.env.SLACK_NOTIFICATION_PATH.trim(),
38-
method: "POST",
39-
headers: {
40-
'Content-Type': 'application/json',
41-
'Content-Length': data.length,
42-
}
43-
}, onErr);
44-
req.on('error', onErr);
45-
req.write(data);
46-
req.end();
47-
}
34+
return new Promise((resolve, reject) => {
35+
const req = https.request({
36+
hostname: "hooks.slack.com",
37+
port: 443,
38+
path: process.env.SLACK_NOTIFICATION_PATH.trim(),
39+
method: "POST",
40+
headers: {
41+
'Content-Type': 'application/json',
42+
'Content-Length': data.length,
43+
}
44+
}, () => resolve());
45+
req.on('error', (error: Error) => reject(error))
46+
req.write(data);
47+
req.end();
48+
})
49+
}

0 commit comments

Comments
 (0)