screwdriver-queue-service 2.0.18 → 2.0.19
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/lib/queue.js +0 -14
- package/package.json +1 -1
- package/plugins/helper.js +30 -0
- package/plugins/queue/scheduler.js +11 -5
- package/plugins/worker/lib/jobs.js +5 -9
package/lib/queue.js
CHANGED
|
@@ -58,20 +58,6 @@ module.exports = class ExecutorQueue {
|
|
|
58
58
|
this.redis[funcName](...args),
|
|
59
59
|
breakerOptions
|
|
60
60
|
);
|
|
61
|
-
this.requestRetryStrategy = response => {
|
|
62
|
-
if (Math.floor(response.statusCode / 100) !== 2) {
|
|
63
|
-
throw new Error('Retry limit reached');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return response;
|
|
67
|
-
};
|
|
68
|
-
this.requestRetryStrategyPostEvent = response => {
|
|
69
|
-
if (Math.floor(response.statusCode / 100) !== 2 && response.statusCode !== 404) {
|
|
70
|
-
throw new Error('Retry limit reached');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return response;
|
|
74
|
-
};
|
|
75
61
|
this.fuseBox = new FuseBox();
|
|
76
62
|
this.fuseBox.addFuse(this.queueBreaker);
|
|
77
63
|
this.fuseBox.addFuse(this.redisBreaker);
|
package/package.json
CHANGED
package/plugins/helper.js
CHANGED
|
@@ -7,6 +7,34 @@ const { queuePrefix } = require('../config/redis');
|
|
|
7
7
|
const RETRY_LIMIT = 3;
|
|
8
8
|
const RETRY_DELAY = 5;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Callback function to retry when HTTP status code is not 2xx
|
|
12
|
+
* @param {Object} response
|
|
13
|
+
* @param {Function} retryWithMergedOptions
|
|
14
|
+
* @return {Object} response
|
|
15
|
+
*/
|
|
16
|
+
function requestRetryStrategy(response) {
|
|
17
|
+
if (Math.floor(response.statusCode / 100) !== 2) {
|
|
18
|
+
throw new Error('Retry limit reached');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return response;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Callback function to retry when HTTP status code is not 2xx and 404
|
|
26
|
+
* @param {Object} response
|
|
27
|
+
* @param {Function} retryWithMergedOptions
|
|
28
|
+
* @return {Object} response
|
|
29
|
+
*/
|
|
30
|
+
function requestRetryStrategyPostEvent(response) {
|
|
31
|
+
if (Math.floor(response.statusCode / 100) !== 2 && response.statusCode !== 404) {
|
|
32
|
+
throw new Error('Retry limit reached');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
37
|
+
|
|
10
38
|
/**
|
|
11
39
|
*
|
|
12
40
|
* @param {String} method
|
|
@@ -241,6 +269,8 @@ async function processHooks(apiUri, token, webhookConfig, retryStrategyFn) {
|
|
|
241
269
|
}
|
|
242
270
|
|
|
243
271
|
module.exports = {
|
|
272
|
+
requestRetryStrategy,
|
|
273
|
+
requestRetryStrategyPostEvent,
|
|
244
274
|
updateBuildStatus,
|
|
245
275
|
updateStepStop,
|
|
246
276
|
getCurrentStep,
|
|
@@ -38,7 +38,7 @@ async function postBuildEvent(executor, eventConfig) {
|
|
|
38
38
|
scope: ['user']
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
const admin = await helper.getPipelineAdmin(token, apiUri, pipelineId,
|
|
41
|
+
const admin = await helper.getPipelineAdmin(token, apiUri, pipelineId, helper.requestRetryStrategy);
|
|
42
42
|
|
|
43
43
|
if (admin) {
|
|
44
44
|
logger.info(
|
|
@@ -64,7 +64,7 @@ async function postBuildEvent(executor, eventConfig) {
|
|
|
64
64
|
buildEvent.buildId = buildId;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
await helper.createBuildEvent(apiUri, jwt, buildEvent,
|
|
67
|
+
await helper.createBuildEvent(apiUri, jwt, buildEvent, helper.requestRetryStrategyPostEvent);
|
|
68
68
|
} else {
|
|
69
69
|
logger.error(
|
|
70
70
|
`POST event for pipeline failed as no admin found: ${pipelineId}:${job.name}:${job.id}:${buildId}`
|
|
@@ -337,7 +337,7 @@ async function start(executor, config) {
|
|
|
337
337
|
apiUri,
|
|
338
338
|
payload
|
|
339
339
|
},
|
|
340
|
-
|
|
340
|
+
helper.requestRetryStrategy
|
|
341
341
|
)
|
|
342
342
|
.catch(err => {
|
|
343
343
|
logger.error(`frozenBuilds: failed to update build status for build ${buildId}: ${err}`);
|
|
@@ -399,7 +399,7 @@ async function start(executor, config) {
|
|
|
399
399
|
apiUri,
|
|
400
400
|
payload: { stats: build.stats, status: 'QUEUED' }
|
|
401
401
|
},
|
|
402
|
-
|
|
402
|
+
helper.requestRetryStrategy
|
|
403
403
|
);
|
|
404
404
|
}
|
|
405
405
|
}
|
|
@@ -730,7 +730,13 @@ async function queueWebhook(executor, webhookConfig) {
|
|
|
730
730
|
'enqueue',
|
|
731
731
|
executor.webhookQueue,
|
|
732
732
|
'sendWebhook',
|
|
733
|
-
JSON.stringify(
|
|
733
|
+
JSON.stringify({
|
|
734
|
+
webhookConfig,
|
|
735
|
+
token: executor.tokenGen({
|
|
736
|
+
service: 'queue',
|
|
737
|
+
scope: ['webhook_worker']
|
|
738
|
+
})
|
|
739
|
+
})
|
|
734
740
|
);
|
|
735
741
|
}
|
|
736
742
|
|
|
@@ -276,18 +276,14 @@ async function clear(cacheConfig) {
|
|
|
276
276
|
|
|
277
277
|
/**
|
|
278
278
|
* Send message to processHooks API
|
|
279
|
-
* @param {String}
|
|
279
|
+
* @param {String} configs as String
|
|
280
280
|
*/
|
|
281
|
-
async function sendWebhook(
|
|
282
|
-
const parsedConfig = JSON.parse(
|
|
281
|
+
async function sendWebhook(configs) {
|
|
282
|
+
const parsedConfig = JSON.parse(configs);
|
|
283
|
+
const { webhookConfig, token } = parsedConfig;
|
|
283
284
|
const apiUri = ecosystem.api;
|
|
284
|
-
const token = executor.tokenGen({
|
|
285
|
-
service: 'queue',
|
|
286
|
-
scope: ['webhook_worker']
|
|
287
|
-
});
|
|
288
|
-
const retryFn = executor.requestRetryStrategyPostEvent;
|
|
289
285
|
|
|
290
|
-
await helper.processHooks(apiUri, token,
|
|
286
|
+
await helper.processHooks(apiUri, token, webhookConfig, helper.requestRetryStrategyPostEvent);
|
|
291
287
|
|
|
292
288
|
return null;
|
|
293
289
|
}
|