screwdriver-queue-service 5.0.4 → 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 +1 -1
- package/plugins/queue/scheduler.js +37 -76
- package/plugins/worker/lib/jobs.js +28 -1
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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:
|
|
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
|
|
445
|
-
|
|
428
|
+
logger.error(`Failed to update build status to QUEUED for build ${buildId}: ${err}`);
|
|
446
429
|
throw err;
|
|
447
430
|
});
|
|
448
|
-
}
|
|
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
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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
|
-
|
|
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',
|
|
275
|
+
await schedule('start', parsedConfig);
|
|
249
276
|
|
|
250
277
|
return null;
|
|
251
278
|
} catch (err) {
|