Skip to content

Commit

Permalink
Merge pull request #1332 from OptimalBits/fix/delete-job-logs-with-au…
Browse files Browse the repository at this point in the history
…toremove

fix: remove logs when autoremoving jobs fixes #1330
  • Loading branch information
manast committed Jun 1, 2019
2 parents 0207f96 + 8522bfa commit 0018090
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/commands/moveToFinished-6.lua
Expand Up @@ -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])
Expand Down
8 changes: 6 additions & 2 deletions test/test_queue.js
Expand Up @@ -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];

Expand All @@ -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();
}
});
Expand Down

0 comments on commit 0018090

Please sign in to comment.