From 673acb2cac9ed0bad77d15452fceaa7818528e85 Mon Sep 17 00:00:00 2001 From: Pritam Paul Date: Thu, 9 Apr 2020 12:49:19 -0400 Subject: [PATCH] fix: Update msg to log job.id (#86) * fix: Update msg to log job.id * fix: log executor methods --- index.js | 68 ++++++++++++++++++++++++++++++++++------------ test/index.test.js | 10 ++++--- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 6eb7623..5e61c34 100644 --- a/index.js +++ b/index.js @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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' @@ -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) { diff --git a/test/index.test.js b/test/index.test.js index 7916a19..affcccc 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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, @@ -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 }); @@ -268,7 +269,8 @@ describe('index test', () => { jobId: testConfig.jobId, startTime: isoTime, job: testJob, - pipeline: testPipeline + pipeline: testPipeline, + pipelineId: testPipeline.id }; sandbox.useFakeTimers(dateNow);