Skip to content

Commit

Permalink
Merge pull request 'feature/redis-notify-error-handling' (#119) from …
Browse files Browse the repository at this point in the history
…feature/redis-notify-error-handling into develop
  • Loading branch information
pavelbannov committed Dec 17, 2024
2 parents 2a2b0b2 + c3b72e0 commit 5a3be03
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
20 changes: 17 additions & 3 deletions common/ASC.Common/Caching/RedisCacheNotify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace ASC.Common.Caching;

[Singleton]
public class RedisCacheNotify<T>(IRedisClient redisCacheClient) : ICacheNotify<T> where T : new()
public class RedisCacheNotify<T>(IRedisClient redisCacheClient, ILogger<RedisCacheNotify<T>> logger) : ICacheNotify<T> where T : new()
{
private readonly IRedisDatabase _redis = redisCacheClient.GetDefaultDatabase();
private readonly ConcurrentDictionary<CacheNotifyAction, ConcurrentBag<Action<T>>> _invocationList = new();
Expand All @@ -39,7 +39,14 @@ public async Task PublishAsync(T obj, CacheNotifyAction action)

foreach (var handler in GetInvocationList(action))
{
handler(obj);
try
{
handler(obj);
}
catch (Exception e)
{
logger.ErrorRedisCacheNotifyPublish(e);
}
}
}

Expand All @@ -49,7 +56,14 @@ public void Subscribe(Action<T> onChange, CacheNotifyAction action)
{
if (i.Id != _instanceId && (i.Action == action || Enum.IsDefined(typeof(CacheNotifyAction), (i.Action & action))))
{
onChange(i.Object);
try
{
onChange(i.Object);
}
catch (Exception e)
{
logger.ErrorRedisCacheNotifySubscribe(e);
}
}

return Task.FromResult(true);
Expand Down
36 changes: 36 additions & 0 deletions common/ASC.Common/Log/RedisCacheNotifyLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// (c) Copyright Ascensio System SIA 2009-2024
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode

namespace ASC.Common.Log;

internal static partial class RedisCacheNotifyLogger
{
[LoggerMessage(LogLevel.Error, "RedisCacheNotify Publish")]
public static partial void ErrorRedisCacheNotifyPublish(this ILogger logger, Exception exception);

[LoggerMessage(LogLevel.Error, "RedisCacheNotify Subscribe")]
public static partial void ErrorRedisCacheNotifySubscribe(this ILogger logger, Exception exception);
}

0 comments on commit 5a3be03

Please sign in to comment.