Skip to content

Commit d7b95aa

Browse files
authored
fix: use BullMQ-safe campaign batch job IDs (#446)
1 parent bd83535 commit d7b95aa

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

apps/web/src/server/service/campaign-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ export class CampaignBatchService {
12491249
await this.batchQueue.add(
12501250
`campaign-${campaignId}`,
12511251
{ campaignId, teamId },
1252-
{ jobId: `campaign-batch:${campaignId}`, ...DEFAULT_QUEUE_OPTIONS },
1252+
{ jobId: `campaign-batch-${campaignId}`, ...DEFAULT_QUEUE_OPTIONS },
12531253
);
12541254
}
12551255
}

apps/web/src/server/service/campaign-service.unit.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ const { mockDb, mockTx, mockUpdateContactSubscription } = vi.hoisted(() => {
2828
findUnique: vi.fn(),
2929
},
3030
campaign: {
31+
findUnique: vi.fn(),
3132
update: vi.fn(),
3233
},
3334
},
3435
mockUpdateContactSubscription: vi.fn(),
3536
};
3637
});
3738

39+
const { mockQueueAdd } = vi.hoisted(() => ({
40+
mockQueueAdd: vi.fn(),
41+
}));
42+
3843
vi.mock("~/server/db", () => ({
3944
db: mockDb,
4045
}));
@@ -55,7 +60,7 @@ vi.mock("~/server/service/contact-service", () => ({
5560

5661
vi.mock("bullmq", () => ({
5762
Queue: class {
58-
add = vi.fn();
63+
add = mockQueueAdd;
5964
},
6065
Worker: class {},
6166
}));
@@ -92,6 +97,7 @@ vi.mock("~/server/logger/log", () => ({
9297
}));
9398

9499
import {
100+
CampaignBatchService,
95101
recordCampaignContactFailure,
96102
subscribeContact,
97103
unsubscribeContact,
@@ -196,6 +202,31 @@ describe("recordCampaignContactFailure", () => {
196202
});
197203
});
198204

205+
describe("CampaignBatchService", () => {
206+
beforeEach(() => {
207+
vi.clearAllMocks();
208+
});
209+
210+
it("queues batches with a BullMQ-safe custom job ID", async () => {
211+
mockDb.campaign.findUnique.mockResolvedValue({
212+
lastSentAt: null,
213+
batchWindowMinutes: 0,
214+
status: "SCHEDULED",
215+
});
216+
217+
await CampaignBatchService.queueBatch({
218+
campaignId: "campaign_1",
219+
teamId: 7,
220+
});
221+
222+
expect(mockQueueAdd).toHaveBeenCalledWith(
223+
"campaign-campaign_1",
224+
{ campaignId: "campaign_1", teamId: 7 },
225+
expect.objectContaining({ jobId: "campaign-batch-campaign_1" }),
226+
);
227+
});
228+
});
229+
199230
describe("campaign contact subscription changes", () => {
200231
beforeEach(() => {
201232
vi.clearAllMocks();

0 commit comments

Comments
 (0)