diff --git a/index.js b/index.js index ba16257..20ab907 100644 --- a/index.js +++ b/index.js @@ -169,19 +169,15 @@ class ExecutorQueue extends Executor { this.multiWorker.start(); this.scheduler.connect().then(() => this.scheduler.start()); - } - /** - * Cleanup any reladed processing - */ - async cleanUp() { - try { - await this.multiWorker.end(); - await this.scheduler.end(); - await this.queue.end(); - } catch (err) { - winston.error(`failed to end executor queue: ${err}`); - } + process.on('SIGTERM', () => { + this.multiWorker.end().catch((err) => { + winston.error(`failed to end the worker: ${err}`); + }).then(() => this.scheduler.end()).catch((err) => { + winston.error(`failed to end the scheduler: ${err}`); + process.exit(128); + }); + }); } /** diff --git a/test/index.test.js b/test/index.test.js index 4fcc748..e5d1e41 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -83,8 +83,7 @@ describe('index test', () => { delDelayed: sinon.stub().resolves(1), connection: { connected: false - }, - end: sinon.stub().resolves() + } }; resqueMock = { Queue: sinon.stub().returns(queueMock), @@ -608,16 +607,6 @@ describe('index test', () => { }); }); - describe('cleanUp', () => { - it('worker.end() is called', () => { - executor.cleanUp().then(() => { - assert.calledWith(spyMultiWorker); - assert.calledWith(spyScheduler); - assert.calledWith(queueMock.end); - }); - }); - }); - describe('stats', () => { it('returns the correct stats', () => { assert.deepEqual(executor.stats(), {