screwdriver-queue-service 2.0.30 → 2.0.33
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": "2.0.
|
|
3
|
+
"version": "2.0.33",
|
|
4
4
|
"description": "Screwdriver Queue Service API",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"directories": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"npm-auto-version": "^1.0.0",
|
|
30
30
|
"redlock": "^4.2.0",
|
|
31
31
|
"screwdriver-aws-producer-service": "^1.3.0",
|
|
32
|
-
"screwdriver-data-schema": "^21.
|
|
32
|
+
"screwdriver-data-schema": "^21.23.0",
|
|
33
33
|
"screwdriver-executor-docker": "^5.0.2",
|
|
34
34
|
"screwdriver-executor-jenkins": "^5.0.1",
|
|
35
35
|
"screwdriver-executor-k8s": "^14.16.0",
|
|
@@ -14,6 +14,7 @@ const RETRY_DELAY = 5;
|
|
|
14
14
|
const EXPIRE_TIME = 1800; // 30 mins
|
|
15
15
|
const TEMPORAL_TOKEN_TIMEOUT = 12 * 60; // 12 hours in minutes
|
|
16
16
|
const TEMPORAL_UNZIP_TOKEN_TIMEOUT = 2 * 60; // 2 hours in minutes
|
|
17
|
+
const BLOCKED_BY_SAME_JOB_WAIT_TIME = 5;
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Posts a new build event to the API
|
|
@@ -253,6 +254,7 @@ async function startPeriodic(executor, config) {
|
|
|
253
254
|
*/
|
|
254
255
|
async function start(executor, config) {
|
|
255
256
|
await executor.connect();
|
|
257
|
+
|
|
256
258
|
const {
|
|
257
259
|
build,
|
|
258
260
|
buildId,
|
|
@@ -383,12 +385,23 @@ async function start(executor, config) {
|
|
|
383
385
|
// Store the config in redis
|
|
384
386
|
await executor.redisBreaker.runCommand('hset', executor.buildConfigTable, buildId, JSON.stringify(config));
|
|
385
387
|
|
|
388
|
+
const blockedBySameJob = reach(config, 'annotations>screwdriver.cd/blockedBySameJob', {
|
|
389
|
+
separator: '>',
|
|
390
|
+
default: true
|
|
391
|
+
});
|
|
392
|
+
const blockedBySameJobWaitTime = reach(config, 'annotations>screwdriver.cd/blockedBySameJobWaitTime', {
|
|
393
|
+
separator: '>',
|
|
394
|
+
default: BLOCKED_BY_SAME_JOB_WAIT_TIME
|
|
395
|
+
});
|
|
396
|
+
|
|
386
397
|
// Note: arguments to enqueue are [queue name, job name, array of args]
|
|
387
398
|
enq = await executor.queueBreaker.runCommand('enqueue', executor.buildQueue, 'start', [
|
|
388
399
|
{
|
|
389
400
|
buildId,
|
|
390
401
|
jobId,
|
|
391
|
-
blockedBy: blockedBy.toString()
|
|
402
|
+
blockedBy: blockedBy.toString(),
|
|
403
|
+
blockedBySameJob,
|
|
404
|
+
blockedBySameJobWaitTime
|
|
392
405
|
}
|
|
393
406
|
]);
|
|
394
407
|
if (buildStats) {
|
|
@@ -17,6 +17,7 @@ const redlock = new Redlock([redis], {
|
|
|
17
17
|
});
|
|
18
18
|
const REDIS_LOCK_TTL = 10000; // in ms
|
|
19
19
|
const BLOCK_TIMEOUT_BUFFER = 30;
|
|
20
|
+
const BLOCKED_BY_SAME_JOB_WAIT_TIME = 5;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* collapse waiting builds and re-enequeue the current build if it is the latest one
|
|
@@ -208,7 +209,32 @@ async function checkBlockingJob({ jobId, buildId }) {
|
|
|
208
209
|
|
|
209
210
|
let blockedBy = this.args[0].blockedBy.split(',').map(jid => `${runningJobsPrefix}${jid}`);
|
|
210
211
|
|
|
211
|
-
|
|
212
|
+
let blockedBySameJob = true;
|
|
213
|
+
let blockedBySameJobWaitTime = BLOCKED_BY_SAME_JOB_WAIT_TIME;
|
|
214
|
+
|
|
215
|
+
if (typeof this.args[0].blockedBySameJob === 'boolean') {
|
|
216
|
+
blockedBySameJob = this.args[0].blockedBySameJob;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (typeof this.args[0].blockedBySameJobWaitTime === 'number') {
|
|
220
|
+
blockedBySameJobWaitTime = this.args[0].blockedBySameJobWaitTime;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const json = await this.queueObject.connection.redis.hget(`${queuePrefix}timeoutConfigs`, lastRunningBuildId);
|
|
224
|
+
const timeoutConfig = JSON.parse(json);
|
|
225
|
+
let notBlockedBySameJob = false;
|
|
226
|
+
|
|
227
|
+
if (!blockedBySameJob && timeoutConfig) {
|
|
228
|
+
const { startTime } = timeoutConfig;
|
|
229
|
+
const diffMs = new Date().getTime() - new Date(startTime).getTime();
|
|
230
|
+
const diffMins = Math.round(diffMs / 60000);
|
|
231
|
+
|
|
232
|
+
if (diffMins >= blockedBySameJobWaitTime) {
|
|
233
|
+
notBlockedBySameJob = true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (notBlockedBySameJob || !enforceBlockedBySelf) {
|
|
212
238
|
blockedBy = blockedBy.filter(key => key !== `${runningJobsPrefix}${jobId}`); // remove itself from blocking list
|
|
213
239
|
}
|
|
214
240
|
|