screwdriver-queue-service 4.0.3 → 4.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": "4.0.3",
3
+ "version": "4.0.5",
4
4
  "description": "Screwdriver Queue Service API",
5
5
  "main": "app.js",
6
6
  "directories": {
@@ -28,7 +28,7 @@
28
28
  "npm-auto-version": "^1.0.0",
29
29
  "redlock": "^4.2.0",
30
30
  "screwdriver-aws-producer-service": "^2.0.0",
31
- "screwdriver-data-schema": "^24.0.0",
31
+ "screwdriver-data-schema": "^24.1.0",
32
32
  "screwdriver-executor-docker": "^7.0.0",
33
33
  "screwdriver-executor-jenkins": "^7.0.0",
34
34
  "screwdriver-executor-k8s": "^16.0.0",
@@ -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,58 @@ 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
+ statusMessageType: 'INFO'
433
+ };
434
+ } else {
435
+ const token = executor.tokenGen(
436
+ Object.assign(tokenConfig, { scope: ['temporal'] }),
437
+ TEMPORAL_TOKEN_TIMEOUT
438
+ );
420
439
 
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
- });
440
+ // set the start time in the queue
441
+ Object.assign(config, { token });
442
+ // Store the config in redis
443
+ await executor.redisBreaker.runCommand('hset', executor.buildConfigTable, buildId, JSON.stringify(config));
429
444
 
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
445
+ const blockedBySameJob = reach(config, 'annotations>screwdriver.cd/blockedBySameJob', {
446
+ separator: '>',
447
+ default: true
448
+ });
449
+ const blockedBySameJobWaitTime = reach(config, 'annotations>screwdriver.cd/blockedBySameJobWaitTime', {
450
+ separator: '>',
451
+ default: BLOCKED_BY_SAME_JOB_WAIT_TIME
452
+ });
453
+
454
+ // Note: arguments to enqueue are [queue name, job name, array of args]
455
+ enq = await executor.queueBreaker.runCommand('enqueue', executor.buildQueue, 'start', [
456
+ {
457
+ buildId,
458
+ jobId,
459
+ blockedBy: blockedBy.toString(),
460
+ blockedBySameJob,
461
+ blockedBySameJobWaitTime
462
+ }
463
+ ]);
464
+ if (buildStats) {
465
+ buildUpdatePayload = { stats: build.stats, status: 'QUEUED' };
438
466
  }
439
- ]);
440
- if (buildStats) {
467
+ }
468
+
469
+ if (buildUpdatePayload) {
441
470
  await helper
442
471
  .updateBuild(
443
472
  {
444
473
  buildId,
445
474
  token: buildToken,
446
475
  apiUri,
447
- payload: { stats: build.stats, status: 'QUEUED' }
476
+ payload: buildUpdatePayload
448
477
  },
449
478
  helper.requestRetryStrategy
450
479
  )