screwdriver-queue-service 2.0.45 → 2.0.47

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/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM node:12
1
+ FROM node:18
2
2
 
3
3
  # Screwdriver Version
4
4
  ARG VERSION=latest
package/Dockerfile.local CHANGED
@@ -1,4 +1,4 @@
1
- FROM node:12
1
+ FROM node:18
2
2
 
3
3
  # Create our application directory
4
4
  RUN mkdir -p /usr/src/app
package/bin/server CHANGED
@@ -20,4 +20,4 @@ server({
20
20
  ecosystem,
21
21
  queueConfig,
22
22
  auth: authConfig
23
- });
23
+ });
@@ -237,6 +237,8 @@ queue:
237
237
  tls: REDIS_TLS_ENABLED
238
238
  slotsRefreshTimeout: REDIS_CLUSTER_SLOTS_REFRESH_TIMEOUT
239
239
  prefix: REDIS_QUEUE_PREFIX
240
+ # whether or not to retrieve from redis that the data needed to start periodic builds
241
+ periodicBuildTableEnabled: PERIODIC_BUILD_TABLE_ENABLED
240
242
 
241
243
  plugins:
242
244
  blockedBy:
@@ -165,6 +165,8 @@ queue:
165
165
  tls: false
166
166
  slotsRefreshTimeout: 1000
167
167
  prefix: ""
168
+ # whether or not to retrieve from redis that the data needed to start periodic builds
169
+ periodicBuildTableEnabled: true
168
170
 
169
171
  plugins:
170
172
  blockedBy:
@@ -1,29 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const config = require('config');
4
-
5
- /**
6
- * convert value to Boolean
7
- * @method convertToBool
8
- * @param {(Boolean|String)} value
9
- * @return {Boolean}
10
- */
11
- function convertToBool(value) {
12
- if (typeof value === 'boolean') {
13
- return value;
14
- }
15
-
16
- // trueList refers to https://yaml.org/type/bool.html
17
- const trueList = ['on', 'true', 'yes', 'y'];
18
- const lowerValue = String(value).toLowerCase();
19
-
20
- return trueList.includes(lowerValue);
21
- }
4
+ const helper = require('../plugins/helper');
22
5
 
23
6
  const rabbitmqConfig = config.get('scheduler').rabbitmq;
24
7
  const { protocol, username, password, host, port, exchange, vhost, connectOptions } = rabbitmqConfig;
25
8
  const amqpURI = `${protocol}://${username}:${password}@${host}:${port}${vhost}`;
26
- const schedulerMode = convertToBool(config.get('scheduler').enabled);
9
+ const schedulerMode = helper.convertToBool(config.get('scheduler').enabled);
27
10
 
28
11
  /**
29
12
  * get configurations for rabbitmq
package/lib/queue.js CHANGED
@@ -30,6 +30,7 @@ module.exports = class ExecutorQueue {
30
30
  this.periodicBuildQueue = `${this.prefix}periodicBuilds`;
31
31
  this.frozenBuildQueue = `${this.prefix}frozenBuilds`;
32
32
  this.buildConfigTable = `${this.prefix}buildConfigs`;
33
+ this.periodicBuildTable = `${this.prefix}periodicBuildConfigs`;
33
34
  this.frozenBuildTable = `${this.prefix}frozenBuildConfigs`;
34
35
  this.tokenGen = null;
35
36
  this.userTokenGen = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-queue-service",
3
- "version": "2.0.45",
3
+ "version": "2.0.47",
4
4
  "description": "Screwdriver Queue Service API",
5
5
  "main": "app.js",
6
6
  "directories": {
package/plugins/helper.js CHANGED
@@ -364,6 +364,24 @@ async function processHooks(apiUri, token, webhookConfig) {
364
364
  });
365
365
  }
366
366
 
367
+ /**
368
+ * convert value to Boolean
369
+ * @method convertToBool
370
+ * @param {(Boolean|String)} value
371
+ * @return {Boolean}
372
+ */
373
+ function convertToBool(value) {
374
+ if (typeof value === 'boolean') {
375
+ return value;
376
+ }
377
+
378
+ // trueList refers to https://yaml.org/type/bool.html
379
+ const trueList = ['on', 'true', 'yes', 'y'];
380
+ const lowerValue = String(value).toLowerCase();
381
+
382
+ return trueList.includes(lowerValue);
383
+ }
384
+
367
385
  module.exports = {
368
386
  requestRetryStrategy,
369
387
  requestRetryStrategyPostEvent,
@@ -376,5 +394,6 @@ module.exports = {
376
394
  getPipelineConfig,
377
395
  updateBuild,
378
396
  notifyJob,
379
- processHooks
397
+ processHooks,
398
+ convertToBool
380
399
  };
@@ -11,6 +11,7 @@ const helper = require('../helper');
11
11
  const { timeOutOfWindows } = require('./utils/freezeWindows');
12
12
  const { queueNamespace } = require('../../config/redis');
13
13
  const ecosystem = Config.get('ecosystem');
14
+ const periodicBuildTableEnabled = helper.convertToBool(Config.get('queue').periodicBuildTableEnabled);
14
15
  const DEFAULT_BUILD_TIMEOUT = 90;
15
16
  const RETRY_LIMIT = 3;
16
17
  const RETRY_DELAY = 5;
@@ -111,9 +112,15 @@ async function postBuildEvent(executor, eventConfig) {
111
112
  async function stopPeriodic(executor, config) {
112
113
  await executor.connect();
113
114
 
114
- return executor.queueBreaker.runCommand('delDelayed', executor.periodicBuildQueue, 'startDelayed', [
115
+ await executor.queueBreaker.runCommand('delDelayed', executor.periodicBuildQueue, 'startDelayed', [
115
116
  { jobId: config.jobId }
116
117
  ]);
118
+
119
+ if (periodicBuildTableEnabled) {
120
+ return executor.redisBreaker.runCommand('hdel', executor.periodicBuildTable, config.jobId);
121
+ }
122
+
123
+ return Promise.resolve();
117
124
  }
118
125
 
119
126
  /**
@@ -193,6 +200,25 @@ async function startPeriodic(executor, config) {
193
200
 
194
201
  const next = cron.next(cron.transform(buildCron, job.id));
195
202
 
203
+ if (periodicBuildTableEnabled) {
204
+ try {
205
+ // Store the config in redis
206
+ await executor.redisBreaker.runCommand(
207
+ 'hset',
208
+ executor.periodicBuildTable,
209
+ job.id,
210
+ JSON.stringify(
211
+ Object.assign(config, {
212
+ isUpdate: false,
213
+ triggerBuild: false
214
+ })
215
+ )
216
+ );
217
+ } catch (err) {
218
+ logger.error(`failed to store the config in Redis for job ${job.id}: ${err}`);
219
+ }
220
+ }
221
+
196
222
  // Note: arguments to enqueueAt are [timestamp, queue name, job name, array of args]
197
223
  let shouldRetry = false;
198
224
 
@@ -454,42 +480,57 @@ async function init(executor) {
454
480
  startDelayed: {
455
481
  perform: async config => {
456
482
  try {
457
- const apiUri = ecosystem.api;
458
483
  const { jobId } = config;
459
484
 
460
485
  logger.info(`Started processing periodic job ${jobId}`);
461
486
 
462
- const buildToken = executor.tokenGen({
463
- jobId,
464
- service: 'queue',
465
- scope: ['build']
466
- });
467
-
468
- const job = await helper.getJobConfig({
469
- jobId,
470
- token: buildToken,
471
- apiUri
472
- });
473
-
474
- const pipelineToken = executor.tokenGen({
475
- pipelineId: job.pipelineId,
476
- service: 'queue',
477
- scope: ['pipeline']
478
- });
479
-
480
- const pipeline = await helper.getPipelineConfig({
481
- pipelineId: job.pipelineId,
482
- token: pipelineToken,
483
- apiUri
484
- });
485
-
486
- const fullConfig = {
487
- pipeline,
488
- job,
489
- apiUri,
490
- isUpdate: false,
491
- triggerBuild: true
492
- };
487
+ let fullConfig;
488
+
489
+ if (periodicBuildTableEnabled) {
490
+ const periodicBuildConfig = await executor.redisBreaker.runCommand(
491
+ 'hget',
492
+ executor.periodicBuildTable,
493
+ jobId
494
+ );
495
+
496
+ fullConfig = Object.assign(JSON.parse(periodicBuildConfig), {
497
+ triggerBuild: true
498
+ });
499
+ } else {
500
+ const apiUri = ecosystem.api;
501
+
502
+ const buildToken = executor.tokenGen({
503
+ jobId,
504
+ service: 'queue',
505
+ scope: ['build']
506
+ });
507
+
508
+ const job = await helper.getJobConfig({
509
+ jobId,
510
+ token: buildToken,
511
+ apiUri
512
+ });
513
+
514
+ const pipelineToken = executor.tokenGen({
515
+ pipelineId: job.pipelineId,
516
+ service: 'queue',
517
+ scope: ['pipeline']
518
+ });
519
+
520
+ const pipeline = await helper.getPipelineConfig({
521
+ pipelineId: job.pipelineId,
522
+ token: pipelineToken,
523
+ apiUri
524
+ });
525
+
526
+ fullConfig = {
527
+ pipeline,
528
+ job,
529
+ apiUri,
530
+ isUpdate: false,
531
+ triggerBuild: true
532
+ };
533
+ }
493
534
 
494
535
  return await startPeriodic(executor, fullConfig);
495
536
  } catch (err) {