Skip to content

Commit

Permalink
feat(queue-events): pass debounceId as a param of debounced event (#2678
Browse files Browse the repository at this point in the history
)
  • Loading branch information
roggervalf authored Aug 1, 2024
1 parent 0a72b19 commit 97fb97a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/classes/queue-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/includes/debounceJob.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/test_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
});
Expand Down

0 comments on commit 97fb97a

Please sign in to comment.