From e92b72ceb520f99fe3f81badc6112cdc9a683003 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Sat, 23 Nov 2024 19:19:24 +0000 Subject: [PATCH] Handle exception SubscribeAsync --- .../Infrastructures/Events/RedisSubscriber.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Infrastructures/Events/RedisSubscriber.cs b/src/Infrastructure/BotSharp.Core/Infrastructures/Events/RedisSubscriber.cs index b93c22a2..67dba26d 100644 --- a/src/Infrastructure/BotSharp.Core/Infrastructures/Events/RedisSubscriber.cs +++ b/src/Infrastructure/BotSharp.Core/Infrastructures/Events/RedisSubscriber.cs @@ -42,23 +42,30 @@ public class RedisSubscriber : IEventSubscriber while (true) { - if (priorityEnabled) + try { - if (await HandleGroupMessage(db, $"{channel}-{EventPriority.High}", group, received) > 0) + if (priorityEnabled) { - continue; - } + if (await HandleGroupMessage(db, $"{channel}-{EventPriority.High}", group, received) > 0) + { + continue; + } - if (await HandleGroupMessage(db, $"{channel}-{EventPriority.Medium}", group, received) > 0) + if (await HandleGroupMessage(db, $"{channel}-{EventPriority.Medium}", group, received) > 0) + { + continue; + } + + await HandleGroupMessage(db, $"{channel}-{EventPriority.Low}", group, received); + } + else { - continue; + await HandleGroupMessage(db, channel, group, received); } - - await HandleGroupMessage(db, $"{channel}-{EventPriority.Low}", group, received); } - else + catch (Exception ex) { - await HandleGroupMessage(db, channel, group, received); + _logger.LogError($"Error processing message: {ex.Message}\r\n{ex}"); } } }