Skip to content

Commit

Permalink
fix: check for enable & archive before starting job (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
d2lam committed Sep 19, 2019
1 parent 4d2e0ae commit dea80f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ class ExecutorQueue extends Executor {
* @param {String} config.apiUri Screwdriver's API
* @param {String} config.jobId JobID that this build belongs to
* @param {String} config.jobName Name of job that this build belongs to
* @param {String} config.jobState ENABLED/DISABLED
* @param {String} config.jobArchived Boolean value of whether job is archived
* @param {String} config.buildId Unique ID for a build
* @param {Object} config.pipeline Pipeline of the job
* @param {Fn} config.tokenGen Function to generate JWT from username, scope and scmContext
Expand All @@ -424,7 +426,9 @@ class ExecutorQueue extends Executor {
*/
async _start(config) {
await this.connect();
const { build, buildId, jobId, blockedBy, freezeWindows, token, apiUri } = config;
const {
build, buildId, jobId, jobState, jobArchived, blockedBy, freezeWindows, token, apiUri
} = config;

if (!this.tokenGen) {
this.tokenGen = config.tokenGen;
Expand All @@ -437,6 +441,12 @@ class ExecutorQueue extends Executor {
jobId
});

// Skip if job is disabled or archived
// Check if jobState & jobArchived exist first, for backward compatibility, TODO: remove later
if ((jobState && jobState !== 'ENABLED') || (jobArchived && jobArchived === true)) {
return Promise.resolve();
}

const currentTime = new Date();
const origTime = new Date(currentTime.getTime());

Expand Down
2 changes: 2 additions & 0 deletions test/data/fullConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
},
"jobId": 777,
"jobName": "main",
"jobState": "ENABLED",
"jobArchived": false,
"buildId": 8609,
"container": "node:4",
"apiUri": "http://api.com",
Expand Down

0 comments on commit dea80f7

Please sign in to comment.