fix(ws): make notification publish fail open with local fallback
This commit is contained in:
@@ -48,13 +48,27 @@ export class WsNotificationService {
|
|||||||
action: 'add' | 'delete',
|
action: 'add' | 'delete',
|
||||||
) {
|
) {
|
||||||
if (this.redisClient) {
|
if (this.redisClient) {
|
||||||
await this.redisClient.publish(
|
try {
|
||||||
REDIS_CHANNEL.FRIEND_CACHE_UPDATE,
|
await this.redisClient.publish(
|
||||||
JSON.stringify({ userId, friendId, action }),
|
REDIS_CHANNEL.FRIEND_CACHE_UPDATE,
|
||||||
);
|
JSON.stringify({ userId, friendId, action }),
|
||||||
} else {
|
);
|
||||||
// Fallback: update locally
|
return;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn(
|
||||||
|
'Redis publish failed for friend cache update; applying local cache update only',
|
||||||
|
error as Error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await this.updateFriendsCacheLocal(userId, friendId, action);
|
await this.updateFriendsCacheLocal(userId, friendId, action);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
'Failed to apply local friend cache update',
|
||||||
|
error as Error,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,13 +103,27 @@ export class WsNotificationService {
|
|||||||
|
|
||||||
async publishActiveDollUpdate(userId: string, dollId: string | null) {
|
async publishActiveDollUpdate(userId: string, dollId: string | null) {
|
||||||
if (this.redisClient) {
|
if (this.redisClient) {
|
||||||
await this.redisClient.publish(
|
try {
|
||||||
REDIS_CHANNEL.ACTIVE_DOLL_UPDATE,
|
await this.redisClient.publish(
|
||||||
JSON.stringify({ userId, dollId }),
|
REDIS_CHANNEL.ACTIVE_DOLL_UPDATE,
|
||||||
);
|
JSON.stringify({ userId, dollId }),
|
||||||
} else {
|
);
|
||||||
// Fallback: update locally
|
return;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn(
|
||||||
|
'Redis publish failed for active doll update; applying local cache update only',
|
||||||
|
error as Error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await this.updateActiveDollCache(userId, dollId);
|
await this.updateActiveDollCache(userId, dollId);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
'Failed to apply local active doll cache update',
|
||||||
|
error as Error,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user