screwdriver-queue-service 2.0.43 → 2.0.45
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/config/redis.js +1 -1
- package/lib/queue.js +0 -1
- package/package.json +1 -1
- package/plugins/helper.js +48 -2
- package/plugins/queue/scheduler.js +46 -39
- package/plugins/worker/worker.js +4 -4
package/config/redis.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const config = require('config');
|
|
4
4
|
|
|
5
5
|
const queueConfig = config.get('queue');
|
|
6
|
-
const connectionType = queueConfig
|
|
6
|
+
const { connectionType } = queueConfig;
|
|
7
7
|
|
|
8
8
|
if (!connectionType || (connectionType !== 'redis' && connectionType !== 'redisCluster')) {
|
|
9
9
|
throw new Error(
|
package/lib/queue.js
CHANGED
|
@@ -30,7 +30,6 @@ module.exports = class ExecutorQueue {
|
|
|
30
30
|
this.periodicBuildQueue = `${this.prefix}periodicBuilds`;
|
|
31
31
|
this.frozenBuildQueue = `${this.prefix}frozenBuilds`;
|
|
32
32
|
this.buildConfigTable = `${this.prefix}buildConfigs`;
|
|
33
|
-
this.periodicBuildTable = `${this.prefix}periodicBuildConfigs`;
|
|
34
33
|
this.frozenBuildTable = `${this.prefix}frozenBuildConfigs`;
|
|
35
34
|
this.tokenGen = null;
|
|
36
35
|
this.userTokenGen = null;
|
package/package.json
CHANGED
package/plugins/helper.js
CHANGED
|
@@ -169,7 +169,7 @@ async function getCurrentStep(stepConfig) {
|
|
|
169
169
|
return null;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
logger.error(`
|
|
172
|
+
logger.error(`GET /v4/builds/${buildId}/steps?status=active returned non 200, ${res.statusCode}, ${res.body}`);
|
|
173
173
|
|
|
174
174
|
throw new Error(`Failed to getCurrentStep with ${res.statusCode} code and ${res.body}`);
|
|
175
175
|
});
|
|
@@ -214,7 +214,7 @@ async function getPipelineAdmin(token, apiUri, pipelineId, retryStrategyFn) {
|
|
|
214
214
|
formatOptions('GET', `${apiUri}/v4/pipelines/${pipelineId}/admin`, token, undefined, retryStrategyFn)
|
|
215
215
|
).then(res => {
|
|
216
216
|
logger.info(
|
|
217
|
-
`
|
|
217
|
+
`GET /v4/pipelines/${pipelineId}/admin completed with attempts, ${res.statusCode}, ${res.attempts}`
|
|
218
218
|
);
|
|
219
219
|
if (res.statusCode === 200) {
|
|
220
220
|
return res.body;
|
|
@@ -247,6 +247,50 @@ async function updateBuild(updateConfig, retryStrategyFn) {
|
|
|
247
247
|
);
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Get job config
|
|
252
|
+
* @param {Object} config
|
|
253
|
+
* @param {Number} config.jobId
|
|
254
|
+
* @param {String} config.token
|
|
255
|
+
* @param {String} config.apiUri
|
|
256
|
+
* @param {Object} retryStrategyFn
|
|
257
|
+
*/
|
|
258
|
+
async function getJobConfig(config, retryStrategyFn) {
|
|
259
|
+
const { jobId, token, apiUri } = config;
|
|
260
|
+
|
|
261
|
+
return request(formatOptions('GET', `${apiUri}/v4/jobs/${jobId}`, token, undefined, retryStrategyFn)).then(res => {
|
|
262
|
+
logger.info(`GET /v4/jobs/${jobId} completed with attempts, ${res.statusCode}, ${res.attempts}`);
|
|
263
|
+
if (res.statusCode === 200) {
|
|
264
|
+
return res.body;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
throw new Error(`Failed to get job config with ${res.statusCode} code and ${JSON.stringify(res.body)}`);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Get pipeline config
|
|
273
|
+
* @param {Object} config
|
|
274
|
+
* @param {Number} config.pipelineId
|
|
275
|
+
* @param {String} config.token
|
|
276
|
+
* @param {String} config.apiUri
|
|
277
|
+
* @param {Object} retryStrategyFn
|
|
278
|
+
*/
|
|
279
|
+
async function getPipelineConfig(config, retryStrategyFn) {
|
|
280
|
+
const { pipelineId, token, apiUri } = config;
|
|
281
|
+
|
|
282
|
+
return request(
|
|
283
|
+
formatOptions('GET', `${apiUri}/v4/pipelines/${pipelineId}`, token, undefined, retryStrategyFn)
|
|
284
|
+
).then(res => {
|
|
285
|
+
logger.info(`GET /v4/pipelines/${pipelineId} completed with attempts, ${res.statusCode}, ${res.attempts}`);
|
|
286
|
+
if (res.statusCode === 200) {
|
|
287
|
+
return res.body;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
throw new Error(`Failed to get pipeline config with ${res.statusCode} code and ${JSON.stringify(res.body)}`);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
250
294
|
/**
|
|
251
295
|
* Notify user with job status
|
|
252
296
|
* @param {Number} jobId
|
|
@@ -328,6 +372,8 @@ module.exports = {
|
|
|
328
372
|
getCurrentStep,
|
|
329
373
|
createBuildEvent,
|
|
330
374
|
getPipelineAdmin,
|
|
375
|
+
getJobConfig,
|
|
376
|
+
getPipelineConfig,
|
|
331
377
|
updateBuild,
|
|
332
378
|
notifyJob,
|
|
333
379
|
processHooks
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const Config = require('config');
|
|
3
4
|
const logger = require('screwdriver-logger');
|
|
4
5
|
const configSchema = require('screwdriver-data-schema').config;
|
|
5
6
|
const TOKEN_CONFIG_SCHEMA = configSchema.tokenConfig;
|
|
@@ -9,6 +10,7 @@ const cron = require('./utils/cron');
|
|
|
9
10
|
const helper = require('../helper');
|
|
10
11
|
const { timeOutOfWindows } = require('./utils/freezeWindows');
|
|
11
12
|
const { queueNamespace } = require('../../config/redis');
|
|
13
|
+
const ecosystem = Config.get('ecosystem');
|
|
12
14
|
const DEFAULT_BUILD_TIMEOUT = 90;
|
|
13
15
|
const RETRY_LIMIT = 3;
|
|
14
16
|
const RETRY_DELAY = 5;
|
|
@@ -20,11 +22,11 @@ const BLOCKED_BY_SAME_JOB_WAIT_TIME = 5;
|
|
|
20
22
|
/**
|
|
21
23
|
* Posts a new build event to the API
|
|
22
24
|
* @method postBuildEvent
|
|
23
|
-
* @param {Object}
|
|
24
|
-
* @param {Number} [
|
|
25
|
-
* @param {Object}
|
|
26
|
-
* @param {Object}
|
|
27
|
-
* @param {String}
|
|
25
|
+
* @param {Object} eventConfig Configuration
|
|
26
|
+
* @param {Number} [eventConfig.eventId] Optional Parent event ID (optional)
|
|
27
|
+
* @param {Object} eventConfig.pipeline Pipeline of the job
|
|
28
|
+
* @param {Object} eventConfig.job Job object to create periodic builds for
|
|
29
|
+
* @param {String} eventConfig.apiUri Base URL of the Screwdriver API
|
|
28
30
|
* @return {Promise}
|
|
29
31
|
*/
|
|
30
32
|
async function postBuildEvent(executor, eventConfig) {
|
|
@@ -109,11 +111,9 @@ async function postBuildEvent(executor, eventConfig) {
|
|
|
109
111
|
async function stopPeriodic(executor, config) {
|
|
110
112
|
await executor.connect();
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
return executor.queueBreaker.runCommand('delDelayed', executor.periodicBuildQueue, 'startDelayed', [
|
|
113
115
|
{ jobId: config.jobId }
|
|
114
116
|
]);
|
|
115
|
-
|
|
116
|
-
return executor.redisBreaker.runCommand('hdel', executor.periodicBuildTable, config.jobId);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
@@ -193,23 +193,6 @@ async function startPeriodic(executor, config) {
|
|
|
193
193
|
|
|
194
194
|
const next = cron.next(cron.transform(buildCron, job.id));
|
|
195
195
|
|
|
196
|
-
try {
|
|
197
|
-
// Store the config in redis
|
|
198
|
-
await executor.redisBreaker.runCommand(
|
|
199
|
-
'hset',
|
|
200
|
-
executor.periodicBuildTable,
|
|
201
|
-
job.id,
|
|
202
|
-
JSON.stringify(
|
|
203
|
-
Object.assign(config, {
|
|
204
|
-
isUpdate: false,
|
|
205
|
-
triggerBuild: false
|
|
206
|
-
})
|
|
207
|
-
)
|
|
208
|
-
);
|
|
209
|
-
} catch (err) {
|
|
210
|
-
logger.error(`failed to store the config in Redis for job ${job.id}: ${err}`);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
196
|
// Note: arguments to enqueueAt are [timestamp, queue name, job name, array of args]
|
|
214
197
|
let shouldRetry = false;
|
|
215
198
|
|
|
@@ -238,7 +221,7 @@ async function startPeriodic(executor, config) {
|
|
|
238
221
|
}
|
|
239
222
|
logger.info(`added to delayed queue for job ${job.id}`);
|
|
240
223
|
|
|
241
|
-
if (triggerBuild) {
|
|
224
|
+
if (triggerBuild && !job.archived) {
|
|
242
225
|
try {
|
|
243
226
|
await postBuildEvent(executor, config);
|
|
244
227
|
} catch (err) {
|
|
@@ -469,22 +452,46 @@ async function init(executor) {
|
|
|
469
452
|
// Jobs object to register the worker with
|
|
470
453
|
const jobs = {
|
|
471
454
|
startDelayed: {
|
|
472
|
-
perform: async
|
|
455
|
+
perform: async config => {
|
|
473
456
|
try {
|
|
474
|
-
|
|
457
|
+
const apiUri = ecosystem.api;
|
|
458
|
+
const { jobId } = config;
|
|
475
459
|
|
|
476
|
-
|
|
477
|
-
'hget',
|
|
478
|
-
executor.periodicBuildTable,
|
|
479
|
-
jobConfig.jobId
|
|
480
|
-
);
|
|
460
|
+
logger.info(`Started processing periodic job ${jobId}`);
|
|
481
461
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
462
|
+
const buildToken = executor.tokenGen({
|
|
463
|
+
jobId,
|
|
464
|
+
service: 'queue',
|
|
465
|
+
scope: ['build']
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
const job = await helper.getJobConfig({
|
|
469
|
+
jobId,
|
|
470
|
+
token: buildToken,
|
|
471
|
+
apiUri
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
const pipelineToken = executor.tokenGen({
|
|
475
|
+
pipelineId: job.pipelineId,
|
|
476
|
+
service: 'queue',
|
|
477
|
+
scope: ['pipeline']
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
const pipeline = await helper.getPipelineConfig({
|
|
481
|
+
pipelineId: job.pipelineId,
|
|
482
|
+
token: pipelineToken,
|
|
483
|
+
apiUri
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
const fullConfig = {
|
|
487
|
+
pipeline,
|
|
488
|
+
job,
|
|
489
|
+
apiUri,
|
|
490
|
+
isUpdate: false,
|
|
491
|
+
triggerBuild: true
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
return await startPeriodic(executor, fullConfig);
|
|
488
495
|
} catch (err) {
|
|
489
496
|
logger.error(`err in startDelayed job: ${err}`);
|
|
490
497
|
throw err;
|
package/plugins/worker/worker.js
CHANGED
|
@@ -43,10 +43,10 @@ const multiWorker = new MultiWorker(
|
|
|
43
43
|
{
|
|
44
44
|
connection: resqueConnection,
|
|
45
45
|
queues: [`${queuePrefix}builds`, `${queuePrefix}cache`, `${queuePrefix}webhooks`],
|
|
46
|
-
minTaskProcessors: workerConfig.minTaskProcessors,
|
|
47
|
-
maxTaskProcessors: workerConfig.maxTaskProcessors,
|
|
48
|
-
checkTimeout: workerConfig.checkTimeout,
|
|
49
|
-
maxEventLoopDelay: workerConfig.maxEventLoopDelay
|
|
46
|
+
minTaskProcessors: parseInt(workerConfig.minTaskProcessors, 10),
|
|
47
|
+
maxTaskProcessors: parseInt(workerConfig.maxTaskProcessors, 10),
|
|
48
|
+
checkTimeout: parseInt(workerConfig.checkTimeout, 10),
|
|
49
|
+
maxEventLoopDelay: parseInt(workerConfig.maxEventLoopDelay, 10)
|
|
50
50
|
},
|
|
51
51
|
jobs
|
|
52
52
|
);
|