screwdriver-queue-service 2.0.28 → 2.0.31

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-queue-service",
3
- "version": "2.0.28",
3
+ "version": "2.0.31",
4
4
  "description": "Screwdriver Queue Service API",
5
5
  "main": "app.js",
6
6
  "directories": {
package/plugins/helper.js CHANGED
@@ -6,6 +6,7 @@ const { queuePrefix } = require('../config/redis');
6
6
 
7
7
  const RETRY_LIMIT = 3;
8
8
  const RETRY_DELAY = 5;
9
+ const calculateDelay = ({ computedValue }) => (computedValue ? RETRY_DELAY * 1000 : 0); // in ms
9
10
 
10
11
  /**
11
12
  * Callback function to retry when HTTP status code is not 2xx
@@ -58,7 +59,7 @@ function formatOptions(method, url, token, json, retryStrategyFn) {
58
59
  if (retryStrategyFn) {
59
60
  const retry = {
60
61
  limit: RETRY_LIMIT,
61
- calculateDelay: ({ computedValue }) => (computedValue ? RETRY_DELAY * 1000 : 0) // in ms
62
+ calculateDelay
62
63
  };
63
64
 
64
65
  if (method === 'POST') {
@@ -255,17 +256,45 @@ async function updateBuild(updateConfig, retryStrategyFn) {
255
256
  * @param {Function} retryStrategyFn
256
257
  * @return {Promise} response or error
257
258
  */
258
- async function processHooks(apiUri, token, webhookConfig, retryStrategyFn) {
259
- return request(formatOptions('POST', `${apiUri}/v4/processHooks`, token, webhookConfig, retryStrategyFn)).then(
260
- res => {
259
+ async function processHooks(apiUri, token, webhookConfig) {
260
+ const options = {
261
+ method: 'POST',
262
+ url: `${apiUri}/v4/processHooks`,
263
+ headers: {
264
+ Authorization: `Bearer ${token}`
265
+ },
266
+ json: webhookConfig,
267
+ retry: {
268
+ limit: RETRY_LIMIT,
269
+ calculateDelay,
270
+ methods: ['POST']
271
+ },
272
+ // Do not retry if the request is received
273
+ errorCodes: ['EADDRINUSE', 'ECONNREFUSED', 'ENOTFOUND', 'ENETUNREACH', 'EAI_AGAIN']
274
+ };
275
+
276
+ return request(options)
277
+ .then(res => {
261
278
  logger.info(`POST /v4/processHooks completed, ${res.statusCode}, ${JSON.stringify(res.body)}`);
262
279
  if ([200, 201, 204].includes(res.statusCode)) {
263
280
  return res;
264
281
  }
265
282
 
266
283
  throw new Error(`Failed to process webhook with ${res.statusCode} code and ${res.body}`);
267
- }
268
- );
284
+ })
285
+ .catch(err => {
286
+ if (err.code === 'ETIMEDOUT') {
287
+ logger.info(`POST /v4/processHooks timed out.`);
288
+ const res = {
289
+ statusCode: 504,
290
+ message: `POST /v4/processHooks timed out.`
291
+ };
292
+
293
+ return res;
294
+ }
295
+
296
+ throw err;
297
+ });
269
298
  }
270
299
 
271
300
  module.exports = {
@@ -62,7 +62,7 @@ const blockedByOptions = {
62
62
  const AWS_REGION_MAP = {
63
63
  north: 'n',
64
64
  west: 'w',
65
- northeast: 'nw',
65
+ northeast: 'ne',
66
66
  east: 'e',
67
67
  south: 's',
68
68
  central: 'c',
@@ -341,7 +341,7 @@ async function sendWebhook(configs) {
341
341
  const { webhookConfig, token } = parsedConfig;
342
342
  const apiUri = ecosystem.api;
343
343
 
344
- await helper.processHooks(apiUri, token, webhookConfig, helper.requestRetryStrategyPostEvent);
344
+ await helper.processHooks(apiUri, token, webhookConfig);
345
345
 
346
346
  return null;
347
347
  }