feature/IO-3492-FCM-Queue-For-Notifications: Finalize
This commit is contained in:
@@ -168,6 +168,7 @@ const loadAppQueue = async ({ pubClient, logger, redisHelpers, ioRedis }) => {
|
||||
|
||||
// Collect notifications by recipientKey
|
||||
const notificationsByRecipient = new Map(); // rk => parsed notifications array
|
||||
const listKeysToDelete = []; // delete only after successful insert+emit
|
||||
|
||||
for (const rk of recipientKeys) {
|
||||
const [user, bodyShopId] = rk.split(":");
|
||||
@@ -188,14 +189,17 @@ const loadAppQueue = async ({ pubClient, logger, redisHelpers, ioRedis }) => {
|
||||
|
||||
if (parsed.length) {
|
||||
notificationsByRecipient.set(rk, parsed);
|
||||
}
|
||||
|
||||
// Cleanup list key after reading
|
||||
await pubClient.del(lk);
|
||||
// IMPORTANT: do NOT delete list yet; only delete after successful insert+emit
|
||||
listKeysToDelete.push(lk);
|
||||
}
|
||||
}
|
||||
|
||||
if (!notificationsByRecipient.size) {
|
||||
devDebugLogger(`No notifications found in lists for jobId ${jobId}, nothing to insert/emit.`);
|
||||
if (listKeysToDelete.length) {
|
||||
await pubClient.del(...listKeysToDelete);
|
||||
}
|
||||
await pubClient.del(rkSet);
|
||||
await pubClient.del(assocHash);
|
||||
await pubClient.del(consolidateFlagKey(jobId));
|
||||
|
||||
Reference in New Issue
Block a user