Fase 1a: fix jobId (BullMQ rechaza ':' en custom job id)
El dry-run contra prod destapo 'Error: Custom Id cannot contain :': el jobId era canal:notificationId. Cambiado a canal_notificationId. Test que lo fija.
This commit is contained in:
parent
6163deecf3
commit
4f8d866226
2 changed files with 24 additions and 2 deletions
|
|
@ -38,9 +38,10 @@ export function createQueues(cfg: Config): Record<Channel, Queue<SendJob>> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Job id = `${channel}:${notificationId}` so BullMQ itself dedupes enqueues:
|
||||
* Job id = `${channel}_${notificationId}` so BullMQ itself dedupes enqueues:
|
||||
* re-polling the same pending doc will not create a second job.
|
||||
* (BullMQ rejects custom job ids containing ':', hence the underscore.)
|
||||
*/
|
||||
export function jobId(job: SendJob): string {
|
||||
return `${job.channel}:${job.notificationId}`;
|
||||
return `${job.channel}_${job.notificationId}`;
|
||||
}
|
||||
|
|
|
|||
21
test/queue.test.ts
Normal file
21
test/queue.test.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { jobId, QUEUE_NAMES } from '../src/queue.js';
|
||||
|
||||
describe('jobId', () => {
|
||||
it('is deterministic per (channel, notificationId) for dedupe', () => {
|
||||
const a = jobId({ channel: 'fcm', notificationId: 'abc' });
|
||||
const b = jobId({ channel: 'fcm', notificationId: 'abc' });
|
||||
expect(a).toBe(b);
|
||||
});
|
||||
it('never contains ":" (BullMQ rejects custom ids with a colon)', () => {
|
||||
expect(jobId({ channel: 'fcm', notificationId: '6a540e689f1e1fd0f9a98788' })).not.toContain(':');
|
||||
expect(jobId({ channel: 'email', notificationId: 'x' })).not.toContain(':');
|
||||
});
|
||||
it('distinguishes channels for the same notification', () => {
|
||||
expect(jobId({ channel: 'fcm', notificationId: 'x' })).not.toBe(jobId({ channel: 'email', notificationId: 'x' }));
|
||||
});
|
||||
it('queue names are colon-free too', () => {
|
||||
expect(QUEUE_NAMES.fcm).not.toContain(':');
|
||||
expect(QUEUE_NAMES.email).not.toContain(':');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue