screwdriver-queue-service 2.0.38 → 2.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugins/helper.js +24 -0
- package/plugins/queue/scheduler.js +22 -1
package/package.json
CHANGED
package/plugins/helper.js
CHANGED
|
@@ -247,6 +247,29 @@ async function updateBuild(updateConfig, retryStrategyFn) {
|
|
|
247
247
|
);
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Notify user with job status
|
|
252
|
+
* @param {Number} jobId
|
|
253
|
+
* @param {String} token
|
|
254
|
+
* @param {Object} payload
|
|
255
|
+
* @param {String} apiUri
|
|
256
|
+
* @param {Object} retryStrategyFn
|
|
257
|
+
*/
|
|
258
|
+
async function notifyJob(notifyConfig, retryStrategyFn) {
|
|
259
|
+
const { token, apiUri, jobId, payload } = notifyConfig;
|
|
260
|
+
|
|
261
|
+
return request(formatOptions('POST', `${apiUri}/v4/jobs/${jobId}/notify`, token, payload, retryStrategyFn)).then(
|
|
262
|
+
res => {
|
|
263
|
+
logger.info(`POST /v4/jobs/${jobId}/notify completed with attempts, ${res.statusCode}, ${res.attempts}`);
|
|
264
|
+
if ([200, 201, 204].includes(res.statusCode)) {
|
|
265
|
+
return res.body;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
throw new Error(`Could not notify job ${jobId} with ${res.statusCode}code and ${JSON.stringify(res.body)}`);
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
250
273
|
/**
|
|
251
274
|
* Post the webhooks process
|
|
252
275
|
* @method processHooks
|
|
@@ -306,5 +329,6 @@ module.exports = {
|
|
|
306
329
|
createBuildEvent,
|
|
307
330
|
getPipelineAdmin,
|
|
308
331
|
updateBuild,
|
|
332
|
+
notifyJob,
|
|
309
333
|
processHooks
|
|
310
334
|
};
|
|
@@ -29,12 +29,13 @@ const BLOCKED_BY_SAME_JOB_WAIT_TIME = 5;
|
|
|
29
29
|
async function postBuildEvent(executor, eventConfig) {
|
|
30
30
|
const { pipeline, job, apiUri, eventId, causeMessage, buildId } = eventConfig;
|
|
31
31
|
const pipelineId = pipeline.id;
|
|
32
|
+
const jobId = job.id;
|
|
32
33
|
|
|
33
34
|
try {
|
|
34
35
|
const token = executor.tokenGen({
|
|
35
36
|
pipelineId,
|
|
36
37
|
service: 'queue',
|
|
37
|
-
jobId
|
|
38
|
+
jobId,
|
|
38
39
|
scmContext: pipeline.scmContext,
|
|
39
40
|
scope: ['user']
|
|
40
41
|
});
|
|
@@ -71,6 +72,26 @@ async function postBuildEvent(executor, eventConfig) {
|
|
|
71
72
|
`POST event for pipeline failed as no admin found: ${pipelineId}:${job.name}:${job.id}:${buildId}`
|
|
72
73
|
);
|
|
73
74
|
|
|
75
|
+
const pipelineToken = executor.tokenGen({
|
|
76
|
+
pipelineId,
|
|
77
|
+
service: 'queue',
|
|
78
|
+
scmContext: pipeline.scmContext,
|
|
79
|
+
scope: ['pipeline']
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const status = 'FAILURE';
|
|
83
|
+
const message = `Pipeline ${pipelineId} does not have admin, unable to start job ${job.name}.`;
|
|
84
|
+
|
|
85
|
+
await helper.notifyJob(
|
|
86
|
+
{
|
|
87
|
+
token: pipelineToken,
|
|
88
|
+
apiUri,
|
|
89
|
+
jobId,
|
|
90
|
+
payload: { status, message }
|
|
91
|
+
},
|
|
92
|
+
helper.requestRetryStrategyPostEvent
|
|
93
|
+
);
|
|
94
|
+
|
|
74
95
|
throw new Error(`Pipeline admin not found, cannot process build ${buildId}`);
|
|
75
96
|
}
|
|
76
97
|
} catch (err) {
|