screwdriver-queue-service 5.0.2 → 5.0.3

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.2",
3
+ "version": "5.0.3",
4
4
  "description": "Screwdriver Queue Service API",
5
5
  "main": "app.js",
6
6
  "directories": {
@@ -422,51 +422,14 @@ async function start(executor, config) {
422
422
  throw value.error;
423
423
  }
424
424
 
425
- let buildUpdatePayload;
426
-
427
425
  if (isVirtualJob(annotations)) {
428
426
  // Bypass execution of the build if the job is virtual
429
- buildUpdatePayload = {
427
+ const buildUpdatePayload = {
430
428
  status: 'SUCCESS',
431
429
  statusMessage: 'Skipped execution of the virtual job',
432
430
  statusMessageType: 'INFO'
433
431
  };
434
- } else {
435
- const token = executor.tokenGen(
436
- Object.assign(tokenConfig, { scope: ['temporal'] }),
437
- TEMPORAL_TOKEN_TIMEOUT
438
- );
439
432
 
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));
444
-
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' };
466
- }
467
- }
468
-
469
- if (buildUpdatePayload) {
470
433
  await helper
471
434
  .updateBuild(
472
435
  {
@@ -478,10 +441,68 @@ async function start(executor, config) {
478
441
  helper.requestRetryStrategy
479
442
  )
480
443
  .catch(err => {
481
- logger.error(`Failed to update build status for build ${buildId}: ${err}`);
444
+ logger.error(`Failed to update virtual build status for build ${buildId}: ${err}`);
482
445
 
483
446
  throw err;
484
447
  });
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
+ }
465
+
466
+ try {
467
+ const token = executor.tokenGen(
468
+ Object.assign(tokenConfig, { scope: ['temporal'] }),
469
+ TEMPORAL_TOKEN_TIMEOUT
470
+ );
471
+
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,
478
+ 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}`);
503
+
504
+ throw err;
505
+ }
485
506
  }
486
507
  }
487
508