Skip to content
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
2 changes: 1 addition & 1 deletion app/server/queues/notification.queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function addSendNotificationJobs(data: SendNotificationJobData[]) {
export async function addFanoutNotificationJob(data: FanoutNotificationJobData) {
const queue = getNotificationQueue()
return queue.add('fanout-notification', data, {
jobId: `fanout:${data.notificationId}`,
jobId: `fanout-${data.notificationId}`,
attempts: 5,
backoff: {
type: 'exponential',
Expand Down
7 changes: 5 additions & 2 deletions app/server/utils/notificationJobId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ interface ChannelJobShape {
to: string
}

// BullMQ rejects custom job ids containing ':' (used as a Redis key separator),
// throwing "Custom Id cannot contain :". Use '-' instead.
export function getSendNotificationJobId(data: DeviceJobShape | ChannelJobShape) {
if (data.deliveryMode === 'device') {
return `notification:${data.notificationId}:device:${data.deviceId}`
return `notification-${data.notificationId}-device-${data.deviceId}`
}

return `notification:${data.notificationId}:channel:${data.channelId}:${data.to}`
const to = data.to.replace(/:/g, '-')
return `notification-${data.notificationId}-channel-${data.channelId}-${to}`
}
19 changes: 17 additions & 2 deletions app/tests/notification-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('getSendNotificationJobId', () => {
title: 'Hello',
body: 'World',
},
})).toBe('notification:n1:device:d1')
})).toBe('notification-n1-device-d1')
})

it('builds deterministic ids for channel jobs', () => {
Expand All @@ -29,6 +29,21 @@ describe('getSendNotificationJobId', () => {
title: 'Hello',
body: 'World',
},
})).toBe('notification:n1:channel:c1:foo@example.com')
})).toBe('notification-n1-channel-c1-foo@example.com')
})

it('sanitizes colons in channel "to" field (e.g. Web Push endpoints)', () => {
expect(getSendNotificationJobId({
deliveryMode: 'channel',
notificationId: 'n1',
appId: 'a1',
channelId: 'c1',
to: 'https://fcm.googleapis.com/fcm/send/abc',
channelType: 'PUSH',
payload: {
title: 'Hello',
body: 'World',
},
})).not.toContain(':')
})
})
Loading