screwdriver-queue-service 4.0.3 → 4.0.4

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": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "description": "Screwdriver Queue Service API",
5
5
  "main": "app.js",
6
6
  "directories": {
@@ -20,6 +20,16 @@ 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
+
23
33
  /**
24
34
  * Posts a new build event to the API
25
35
  * @method postBuildEvent
@@ -300,7 +310,8 @@ async function start(executor, config) {
300
310
  apiUri,
301
311
  pipeline,
302
312
  isPR,
303
- prParentJobId
313
+ prParentJobId,
314
+ annotations
304
315
  } = config;
305
316
  const forceStart = /\[(force start)\]/.test(causeMessage);
306
317
 
@@ -411,40 +422,57 @@ async function start(executor, config) {
411
422
  throw value.error;
412
423
  }
413
424
 
414
- const token = executor.tokenGen(Object.assign(tokenConfig, { scope: ['temporal'] }), TEMPORAL_TOKEN_TIMEOUT);
425
+ let buildUpdatePayload;
415
426
 
416
- // set the start time in the queue
417
- Object.assign(config, { token });
418
- // Store the config in redis
419
- await executor.redisBreaker.runCommand('hset', executor.buildConfigTable, buildId, JSON.stringify(config));
427
+ if (isVirtualJob(annotations)) {
428
+ // Bypass execution of the build if the job is virtual
429
+ buildUpdatePayload = {
430
+ status: 'SUCCESS',
431
+ statusMessage: 'Skipped execution of the virtual job'
432
+ };
433
+ } else {
434
+ const token = executor.tokenGen(
435
+ Object.assign(tokenConfig, { scope: ['temporal'] }),
436
+ TEMPORAL_TOKEN_TIMEOUT
437
+ );
420
438
 
421
- const blockedBySameJob = reach(config, 'annotations>screwdriver.cd/blockedBySameJob', {
422
- separator: '>',
423
- default: true
424
- });
425
- const blockedBySameJobWaitTime = reach(config, 'annotations>screwdriver.cd/blockedBySameJobWaitTime', {
426
- separator: '>',
427
- default: BLOCKED_BY_SAME_JOB_WAIT_TIME
428
- });
439
+ // set the start time in the queue
440
+ Object.assign(config, { token });
441
+ // Store the config in redis
442
+ await executor.redisBreaker.runCommand('hset', executor.buildConfigTable, buildId, JSON.stringify(config));
429
443
 
430
- // Note: arguments to enqueue are [queue name, job name, array of args]
431
- enq = await executor.queueBreaker.runCommand('enqueue', executor.buildQueue, 'start', [
432
- {
433
- buildId,
434
- jobId,
435
- blockedBy: blockedBy.toString(),
436
- blockedBySameJob,
437
- blockedBySameJobWaitTime
444
+ const blockedBySameJob = reach(config, 'annotations>screwdriver.cd/blockedBySameJob', {
445
+ separator: '>',
446
+ default: true
447
+ });
448
+ const blockedBySameJobWaitTime = reach(config, 'annotations>screwdriver.cd/blockedBySameJobWaitTime', {
449
+ separator: '>',
450
+ default: BLOCKED_BY_SAME_JOB_WAIT_TIME
451
+ });
452
+
453
+ // Note: arguments to enqueue are [queue name, job name, array of args]
454
+ enq = await executor.queueBreaker.runCommand('enqueue', executor.buildQueue, 'start', [
455
+ {
456
+ buildId,
457
+ jobId,
458
+ blockedBy: blockedBy.toString(),
459
+ blockedBySameJob,
460
+ blockedBySameJobWaitTime
461
+ }
462
+ ]);
463
+ if (buildStats) {
464
+ buildUpdatePayload = { stats: build.stats, status: 'QUEUED' };
438
465
  }
439
- ]);
440
- if (buildStats) {
466
+ }
467
+
468
+ if (buildUpdatePayload) {
441
469
  await helper
442
470
  .updateBuild(
443
471
  {
444
472
  buildId,
445
473
  token: buildToken,
446
474
  apiUri,
447
- payload: { stats: build.stats, status: 'QUEUED' }
475
+ payload: buildUpdatePayload
448
476
  },
449
477
  helper.requestRetryStrategy
450
478
  )