screwdriver-queue-service 5.0.3 → 5.0.5

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": "5.0.3",
3
+ "version": "5.0.5",
4
4
  "description": "Screwdriver Queue Service API",
5
5
  "main": "app.js",
6
6
  "directories": {
@@ -20,16 +20,6 @@ const TEMPORAL_TOKEN_TIMEOUT = 12 * 60; // 12 hours in minutes
20
20
  const TEMPORAL_UNZIP_TOKEN_TIMEOUT = 2 * 60; // 2 hours in minutes
21
21
  const BLOCKED_BY_SAME_JOB_WAIT_TIME = 5;
22
22
 
23
- /**
24
- * Checks whether the job associated with the build is virtual or not
25
- * @method isVirtualJob
26
- * @param {Object} annotations Job Annotations
27
- * @return {Boolean}
28
- */
29
- function isVirtualJob(annotations) {
30
- return annotations && annotations['screwdriver.cd/virtualJob'];
31
- }
32
-
33
23
  /**
34
24
  * Posts a new build event to the API
35
25
  * @method postBuildEvent
@@ -310,8 +300,7 @@ async function start(executor, config) {
310
300
  apiUri,
311
301
  pipeline,
312
302
  isPR,
313
- prParentJobId,
314
- annotations
303
+ prParentJobId
315
304
  } = config;
316
305
  const forceStart = /\[(force start)\]/.test(causeMessage);
317
306
 
@@ -422,87 +411,59 @@ async function start(executor, config) {
422
411
  throw value.error;
423
412
  }
424
413
 
425
- if (isVirtualJob(annotations)) {
426
- // Bypass execution of the build if the job is virtual
427
- const buildUpdatePayload = {
428
- status: 'SUCCESS',
429
- statusMessage: 'Skipped execution of the virtual job',
430
- statusMessageType: 'INFO'
431
- };
414
+ const token = executor.tokenGen(Object.assign(tokenConfig, { scope: ['temporal'] }), TEMPORAL_TOKEN_TIMEOUT);
432
415
 
416
+ if (buildStats) {
433
417
  await helper
434
418
  .updateBuild(
435
419
  {
436
420
  buildId,
437
421
  token: buildToken,
438
422
  apiUri,
439
- payload: buildUpdatePayload
423
+ payload: { stats: build.stats, status: 'QUEUED' }
440
424
  },
441
425
  helper.requestRetryStrategy
442
426
  )
443
427
  .catch(err => {
444
- logger.error(`Failed to update virtual build status for build ${buildId}: ${err}`);
445
-
428
+ logger.error(`Failed to update build status to QUEUED for build ${buildId}: ${err}`);
446
429
  throw err;
447
430
  });
448
- } else {
449
- if (buildStats) {
450
- await helper
451
- .updateBuild(
452
- {
453
- buildId,
454
- token: buildToken,
455
- apiUri,
456
- payload: { stats: build.stats, status: 'QUEUED' }
457
- },
458
- helper.requestRetryStrategy
459
- )
460
- .catch(err => {
461
- logger.error(`Failed to update build status to QUEUED for build ${buildId}: ${err}`);
462
- throw err;
463
- });
464
- }
431
+ }
465
432
 
466
- try {
467
- const token = executor.tokenGen(
468
- Object.assign(tokenConfig, { scope: ['temporal'] }),
469
- TEMPORAL_TOKEN_TIMEOUT
470
- );
433
+ try {
434
+ // set the start time in the queue
435
+ Object.assign(config, { token });
436
+ // Store the config in redis
437
+ await executor.redisBreaker.runCommand('hset', executor.buildConfigTable, buildId, JSON.stringify(config));
438
+
439
+ const blockedBySameJob = reach(config, 'annotations>screwdriver.cd/blockedBySameJob', {
440
+ separator: '>',
441
+ default: true
442
+ });
443
+ const blockedBySameJobWaitTime = reach(config, 'annotations>screwdriver.cd/blockedBySameJobWaitTime', {
444
+ separator: '>',
445
+ default: BLOCKED_BY_SAME_JOB_WAIT_TIME
446
+ });
447
+ const virtualJob = reach(config, 'annotations>screwdriver.cd/virtualJob', {
448
+ separator: '>',
449
+ default: false
450
+ });
471
451
 
472
- // set the start time in the queue
473
- Object.assign(config, { token });
474
- // Store the config in redis
475
- await executor.redisBreaker.runCommand(
476
- 'hset',
477
- executor.buildConfigTable,
452
+ // Note: arguments to enqueue are [queue name, job name, array of args]
453
+ enq = await executor.queueBreaker.runCommand('enqueue', executor.buildQueue, 'start', [
454
+ {
478
455
  buildId,
479
- JSON.stringify(config)
480
- );
481
-
482
- const blockedBySameJob = reach(config, 'annotations>screwdriver.cd/blockedBySameJob', {
483
- separator: '>',
484
- default: true
485
- });
486
- const blockedBySameJobWaitTime = reach(config, 'annotations>screwdriver.cd/blockedBySameJobWaitTime', {
487
- separator: '>',
488
- default: BLOCKED_BY_SAME_JOB_WAIT_TIME
489
- });
490
-
491
- // Note: arguments to enqueue are [queue name, job name, array of args]
492
- enq = await executor.queueBreaker.runCommand('enqueue', executor.buildQueue, 'start', [
493
- {
494
- buildId,
495
- jobId,
496
- blockedBy: blockedBy.toString(),
497
- blockedBySameJob,
498
- blockedBySameJobWaitTime
499
- }
500
- ]);
501
- } catch (err) {
502
- logger.error(`Redis enqueue failed for build ${buildId}: ${err}`);
456
+ jobId,
457
+ blockedBy: blockedBy.toString(),
458
+ blockedBySameJob,
459
+ blockedBySameJobWaitTime,
460
+ virtualJob
461
+ }
462
+ ]);
463
+ } catch (err) {
464
+ logger.error(`Redis enqueue failed for build ${buildId}: ${err}`);
503
465
 
504
- throw err;
505
- }
466
+ throw err;
506
467
  }
507
468
  }
508
469
 
@@ -244,8 +244,35 @@ async function schedule(job, buildConfig) {
244
244
  async function start(buildConfig) {
245
245
  try {
246
246
  const fullBuildConfig = await redis.hget(`${queuePrefix}buildConfigs`, buildConfig.buildId);
247
+ const parsedConfig = fullBuildConfig && JSON.parse(fullBuildConfig);
248
+
249
+ // Short-circuit virtual jobs: mark success and skip executor start
250
+ if (buildConfig.virtualJob) {
251
+ const payload = {
252
+ status: 'SUCCESS',
253
+ statusMessage: 'Skipped execution of the virtual job',
254
+ statusMessageType: 'INFO'
255
+ };
256
+
257
+ // Preserve any queued stats (e.g. queueEnterTime) if present
258
+ if (parsedConfig && parsedConfig.stats) {
259
+ payload.stats = parsedConfig.stats;
260
+ }
261
+
262
+ await helper.updateBuild(
263
+ {
264
+ buildId: buildConfig.buildId,
265
+ token: parsedConfig && parsedConfig.token,
266
+ apiUri: parsedConfig && parsedConfig.apiUri,
267
+ payload
268
+ },
269
+ helper.requestRetryStrategy
270
+ );
271
+
272
+ return null;
273
+ }
247
274
 
248
- await schedule('start', JSON.parse(fullBuildConfig));
275
+ await schedule('start', parsedConfig);
249
276
 
250
277
  return null;
251
278
  } catch (err) {