From 97fb97a054d6cebbe1d7ff1cb5c46d7da1c018d8 Mon Sep 17 00:00:00 2001 From: Rogger Valverde Date: Wed, 31 Jul 2024 19:28:18 -0600 Subject: [PATCH] feat(queue-events): pass debounceId as a param of debounced event (#2678) --- src/classes/queue-events.ts | 4 ++-- src/commands/includes/debounceJob.lua | 2 +- tests/test_events.ts | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/classes/queue-events.ts b/src/classes/queue-events.ts index 27201c26ca..1fdb028f50 100644 --- a/src/classes/queue-events.ts +++ b/src/classes/queue-events.ts @@ -48,9 +48,9 @@ export interface QueueEventsListener extends IoredisListener { /** * Listen to 'debounced' event. * - * This event is triggered when a job is debounced because debouncedId still existed. + * This event is triggered when a job is debounced because debounceId still existed. */ - debounced: (args: { jobId: string }, id: string) => void; + debounced: (args: { jobId: string; debounceId: string }, id: string) => void; /** * Listen to 'delayed' event. diff --git a/src/commands/includes/debounceJob.lua b/src/commands/includes/debounceJob.lua index b40f4cb8db..aa4cf089dd 100644 --- a/src/commands/includes/debounceJob.lua +++ b/src/commands/includes/debounceJob.lua @@ -15,7 +15,7 @@ local function debounceJob(prefixKey, debounceOpts, jobId, debounceKey, eventsKe if debounceKeyExists then local currentDebounceJobId = rcall('GET', debounceKey) rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", - "debounced", "jobId", currentDebounceJobId) + "debounced", "jobId", currentDebounceJobId, "debounceId", debounceId) return currentDebounceJobId end end diff --git a/tests/test_events.ts b/tests/test_events.ts index 41d99c2839..28bcade1f7 100644 --- a/tests/test_events.ts +++ b/tests/test_events.ts @@ -411,11 +411,13 @@ describe('events', function () { let debouncedCounter = 0; let secondJob; - queueEvents.on('debounced', ({ jobId }) => { + queueEvents.on('debounced', ({ jobId, debounceId }) => { if (debouncedCounter > 1) { expect(jobId).to.be.equal(secondJob.id); + expect(debounceId).to.be.equal('a1'); } else { expect(jobId).to.be.equal(job.id); + expect(debounceId).to.be.equal('a1'); } debouncedCounter++; });