From 8522bfaa13da28379cd143d368a5184b81efa303 Mon Sep 17 00:00:00 2001 From: Manuel Astudillo Date: Sat, 1 Jun 2019 12:24:01 +0200 Subject: [PATCH] fix: remove logs when autoremoving jobs fixes #1330 --- lib/commands/moveToFinished-6.lua | 6 ++++-- test/test_queue.js | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/commands/moveToFinished-6.lua b/lib/commands/moveToFinished-6.lua index 5542aed5a..a19827539 100644 --- a/lib/commands/moveToFinished-6.lua +++ b/lib/commands/moveToFinished-6.lua @@ -59,12 +59,14 @@ if rcall("EXISTS", KEYS[3]) == 1 then -- // Make sure job exists local jobIds = rcall("ZREVRANGE", KEYS[2], start, -1) for i, jobId in ipairs(jobIds) do local jobKey = ARGV[9] .. jobId - rcall("DEL", jobKey) + local jobLogKey = jobKey .. ':logs' + rcall("DEL", jobKey, jobLogKey) end rcall("ZREMRANGEBYRANK", KEYS[2], 0, -removeJobs); end else - rcall("DEL", KEYS[3]) + local jobLogKey = KEYS[3] .. ':logs' + rcall("DEL", KEYS[3], jobLogKey) end rcall("PUBLISH", KEYS[2], ARGV[7]) diff --git a/test/test_queue.js b/test/test_queue.js index a67071a99..0e69a7a68 100644 --- a/test/test_queue.js +++ b/test/test_queue.js @@ -459,7 +459,9 @@ describe('Queue', () => { it('should keep specified number of jobs after completed with removeOnComplete', async () => { const keepJobs = 3; - queue.process(() => {}); + queue.process(async job => { + await job.log('test log'); + }); const datas = [0, 1, 2, 3, 4, 5, 6, 7, 8]; @@ -479,14 +481,16 @@ describe('Queue', () => { await Promise.all( jobIds.map(async (jobId, index) => { const job = await queue.getJob(jobId); + const logs = await queue.getJobLogs(jobId); if (index >= datas.length - keepJobs) { expect(job).to.not.be.equal(null); + expect(logs.logs).to.not.be.empty; } else { expect(job).to.be.equal(null); + expect(logs.logs).to.be.empty; } }) ); - resolve(); } });