screwdriver-queue-service 2.0.17 → 2.0.18

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.17",
3
+ "version": "2.0.18",
4
4
  "description": "Screwdriver Queue Service API",
5
5
  "main": "app.js",
6
6
  "directories": {
package/plugins/helper.js CHANGED
@@ -218,11 +218,34 @@ async function updateBuild(updateConfig, retryStrategyFn) {
218
218
  );
219
219
  }
220
220
 
221
+ /**
222
+ * Post the webhooks process
223
+ * @method processHooks
224
+ * @param {String} apiUri
225
+ * @param {String} token
226
+ * @param {String} webhookConfig as JSON format
227
+ * @param {Function} retryStrategyFn
228
+ * @return {Promise} response or error
229
+ */
230
+ async function processHooks(apiUri, token, webhookConfig, retryStrategyFn) {
231
+ return request(formatOptions('POST', `${apiUri}/v4/processHooks`, token, webhookConfig, retryStrategyFn)).then(
232
+ res => {
233
+ logger.info(`POST /v4/processHooks completed, ${res.statusCode}, ${JSON.stringify(res.body)}`);
234
+ if ([200, 201, 204].includes(res.statusCode)) {
235
+ return res;
236
+ }
237
+
238
+ throw new Error(`Failed to process webhook with ${res.statusCode} code and ${res.body}`);
239
+ }
240
+ );
241
+ }
242
+
221
243
  module.exports = {
222
244
  updateBuildStatus,
223
245
  updateStepStop,
224
246
  getCurrentStep,
225
247
  createBuildEvent,
226
248
  getPipelineAdmin,
227
- updateBuild
249
+ updateBuild,
250
+ processHooks
228
251
  };
@@ -7,6 +7,7 @@ const hoek = require('@hapi/hoek');
7
7
  const ExecutorRouter = require('screwdriver-executor-router');
8
8
  const logger = require('screwdriver-logger');
9
9
  const AWSProducer = require('screwdriver-aws-producer-service');
10
+ const helper = require('../../helper');
10
11
  const { BlockedBy } = require('./BlockedBy');
11
12
  const { Filter } = require('./Filter');
12
13
  const { CacheFilter } = require('./CacheFilter');
@@ -17,7 +18,7 @@ const { amqpURI, exchange, connectOptions } = rabbitmqConf.getConfig();
17
18
  const kafkaEnabled = config.get('kafka').enabled === 'true';
18
19
 
19
20
  const RETRY_LIMIT = 3;
20
- // This is in milliseconds, reference: https://github.com/taskrabbit/node-resque/blob/master/lib/plugins/Retry.js#L12
21
+ // This is in milliseconds, reference: https://github.com/actionhero/node-resque/blob/2ffdf0/lib/plugins/Retry.js#L12
21
22
  const RETRY_DELAY = 5 * 1000;
22
23
  const redis = new Redis(connectionDetails.port, connectionDetails.host, connectionDetails.options);
23
24
 
@@ -273,6 +274,24 @@ async function clear(cacheConfig) {
273
274
  return null;
274
275
  }
275
276
 
277
+ /**
278
+ * Send message to processHooks API
279
+ * @param {String} webhookConfig as String
280
+ */
281
+ async function sendWebhook(webhookConfig) {
282
+ const parsedConfig = JSON.parse(webhookConfig);
283
+ const apiUri = ecosystem.api;
284
+ const token = executor.tokenGen({
285
+ service: 'queue',
286
+ scope: ['webhook_worker']
287
+ });
288
+ const retryFn = executor.requestRetryStrategyPostEvent;
289
+
290
+ await helper.processHooks(apiUri, token, parsedConfig, retryFn);
291
+
292
+ return null;
293
+ }
294
+
276
295
  module.exports = {
277
296
  start: {
278
297
  plugins: [Filter, 'Retry', BlockedBy],
@@ -295,5 +314,12 @@ module.exports = {
295
314
  Retry: retryOptions
296
315
  },
297
316
  perform: clear
317
+ },
318
+ sendWebhook: {
319
+ plugins: ['Retry'],
320
+ pluginOptions: {
321
+ Retry: retryOptions
322
+ },
323
+ perform: sendWebhook
298
324
  }
299
325
  };
@@ -42,7 +42,7 @@ async function shutDownAll(worker, scheduler) {
42
42
  const multiWorker = new NodeResque.MultiWorker(
43
43
  {
44
44
  connection: connectionDetails,
45
- queues: [`${queuePrefix}builds`, `${queuePrefix}cache`],
45
+ queues: [`${queuePrefix}builds`, `${queuePrefix}cache`, `${queuePrefix}webhooks`],
46
46
  minTaskProcessors: workerConfig.minTaskProcessors,
47
47
  maxTaskProcessors: workerConfig.maxTaskProcessors,
48
48
  checkTimeout: workerConfig.checkTimeout,