Skip to content

Commit

Permalink
fix: Update msg to log job.id (#86)
Browse files Browse the repository at this point in the history
* fix: Update msg to log job.id

* fix: log executor methods
  • Loading branch information
pritamstyz4ever authored Apr 9, 2020
1 parent ef8c26a commit 673acb2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 22 deletions.
68 changes: 50 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ class ExecutorQueue extends Executor {
* @return {Promise}
*/
async _startPeriodic(config) {
return this.api(config, {
const options = {
path: '/v1/queue/message?type=periodic',
method: 'POST',
body: config
});
};

logger.info(`${options.method} ${options.path} for pipeline ${config.pipeline.id}:${config.job.id}`);

return this.api(config, options);
}

/**
Expand All @@ -42,11 +46,15 @@ class ExecutorQueue extends Executor {
* @return {Promise}
*/
async _stopPeriodic(config) {
return this.api(config, {
const options = {
path: '/v1/queue/message?type=periodic',
method: 'DELETE',
body: config
});
};

logger.info(`${options.method} ${options.path} for pipeline ${config.pipelineId}:${config.jobId}`);

return this.api(config, options);
}

/**
Expand All @@ -56,11 +64,15 @@ class ExecutorQueue extends Executor {
* @return {Promise}
*/
async _startFrozen(config) {
return this.api(config, {
const options = {
path: '/v1/queue/message?type=frozen',
method: 'POST',
body: config
});
};

logger.info(`${options.method} ${options.path} for pipeline ${config.pipelineId}:${config.jobId}`);

return this.api(config, options);
}

/**
Expand All @@ -71,11 +83,15 @@ class ExecutorQueue extends Executor {
* @return {Promise}
*/
async _stopFrozen(config) {
return this.api(config, {
const options = {
path: '/v1/queue/message?type=frozen',
method: 'DELETE',
body: config
});
};

logger.info(`${options.method} ${options.path} for pipeline ${config.pipelineId}:${config.jobId}`);

return this.api(config, options);
}

/**
Expand All @@ -88,11 +104,15 @@ class ExecutorQueue extends Executor {
* @return {Promise}
*/
async _startTimer(config) {
return this.api(config, {
const options = {
path: '/v1/queue/message?type=timer',
method: 'POST',
body: config
});
};

logger.info(`${options.method} ${options.path} for pipeline ${config.pipelineId}:${config.jobId}`);

return this.api(config, options);
}

/**
Expand All @@ -103,11 +123,15 @@ class ExecutorQueue extends Executor {
* @return {Promise}
*/
async _stopTimer(config) {
return this.api(config, {
const options = {
path: '/v1/queue/message?type=timer',
method: 'DELETE',
body: config
});
};

logger.info(`${options.method} ${options.path} for pipeline ${config.pipelineId}:${config.jobId}`);

return this.api(config, options);
}

/**
Expand All @@ -133,11 +157,15 @@ class ExecutorQueue extends Executor {
* @return {Promise}
*/
async _start(config) {
return this.api(config, {
const options = {
path: '/v1/queue/message',
method: 'POST',
body: config
});
};

logger.info(`${options.method} ${options.path} for pipeline ${config.pipelineId}:${config.jobId}`);

return this.api(config, options);
}

/**
Expand All @@ -150,11 +178,15 @@ class ExecutorQueue extends Executor {
* @return {Promise}
*/
async _stop(config) {
return this.api(config, {
const options = {
path: '/v1/queue/message',
method: 'DELETE',
body: config
});
};

logger.info(`${options.method} ${options.path} for pipeline ${config.pipelineId}:${config.jobId}`);

return this.api(config, options);
}

/**
Expand All @@ -163,6 +195,8 @@ class ExecutorQueue extends Executor {
* @param {Response} Object Object containing stats for the executor
*/
stats(config) {
logger.info('GET /v1/queue/stats for pipeline');

return this.api(config, {
path: '/v1/queue/stats',
method: 'GET'
Expand Down Expand Up @@ -190,8 +224,6 @@ class ExecutorQueue extends Executor {
...args
};

logger.info(`${options.method} ${options.path} for pipeline ${config.pipelineId}:${config.jobId}`);

return new Promise((resolve, reject) => {
requestretry(options, (err, response) => {
if (!err) {
Expand Down
10 changes: 6 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('index test', () => {
describe('_startPeriodic', done => {
it('Calls api to start periodic build', () => {
mockRequest.yieldsAsync(null, { statusCode: 200 });
const periodicConfig = { ...testConfig, username: 'admin' };
const periodicConfig = { ...testConfig, username: 'admin', pipeline: { id: 123 }, job: { id: 777 } };

const options = {
...requestOptions,
Expand Down Expand Up @@ -235,13 +235,14 @@ describe('index test', () => {
jobId: testConfig.jobId,
startTime: isoTime,
job: testJob,
pipeline: testPipeline
pipeline: testPipeline,
pipelineId: testPipeline.id
};

sandbox.useFakeTimers(dateNow);
Object.assign(requestOptions, {
url: 'http://localhost/v1/queue/message?type=timer',
method: 'DEELTE',
method: 'DELETE',
body: timerConfig
});

Expand All @@ -268,7 +269,8 @@ describe('index test', () => {
jobId: testConfig.jobId,
startTime: isoTime,
job: testJob,
pipeline: testPipeline
pipeline: testPipeline,
pipelineId: testPipeline.id
};

sandbox.useFakeTimers(dateNow);
Expand Down

0 comments on commit 673acb2

Please sign in to comment.