Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(events): do not publish removed event on non-existent jobs #2227

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/commands/removeJob-1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ local function removeJob( prefix, jobId, parentKey, removeChildren)

local prev = removeJobFromAnyState(prefix, jobId)

rcall("DEL", jobKey, jobKey .. ":logs", jobKey .. ":dependencies", jobKey .. ":processed")

rcall("XADD", prefix .. "events", "*", "event", "removed", "jobId", jobId, "prev", prev);
if rcall("DEL", jobKey, jobKey .. ":logs", jobKey .. ":dependencies", jobKey .. ":processed") > 0 then
rcall("XADD", prefix .. "events", "*", "event", "removed", "jobId", jobId, "prev", prev)
end
end

local prefix = KEYS[1]
Expand Down
28 changes: 26 additions & 2 deletions tests/test_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,28 @@ describe('events', function () {
await worker.close();
});

describe('when jobs removal is attempted on non-existed records', async () => {
it('should not publish removed events', async () => {
const numRemovals = 100;
const trimmedQueue = new Queue(queueName, {
connection,
});

const client = await trimmedQueue.client;

for (let i = 0; i < numRemovals; i++) {
await trimmedQueue.remove(i.toString());
}

const eventsLength = await client.xlen(trimmedQueue.keys.events);

expect(eventsLength).to.be.eql(0);

await trimmedQueue.close();
await removeAllQueueData(new IORedis(), queueName);
});
});

describe('when maxLen is 0', function () {
it('should trim events automatically', async () => {
const trimmedQueue = new Queue(queueName, {
Expand Down Expand Up @@ -657,7 +679,7 @@ describe('events', function () {
});
});

describe('when jobs are retried inmediately', function () {
describe('when jobs are retried immediately', function () {
it('should trim events so its length is at least the threshold', async () => {
const numJobs = 80;
const trimmedQueue = new Queue(queueName, {
Expand Down Expand Up @@ -685,7 +707,9 @@ describe('events', function () {

const waitCompletedEvent = new Promise<void>(resolve => {
queueEvents.on('waiting', async ({ jobId, prev }) => {
if (prev === 'failed' && jobId === numJobs + '') {resolve();}
if (prev === 'failed' && jobId === numJobs + '') {
resolve();
}
});
});

Expand Down