Skip to content

Commit

Permalink
Merge pull request #102 from Poltuu/up
Browse files Browse the repository at this point in the history
Up
  • Loading branch information
Poltuu authored Jun 16, 2020
2 parents 1aca6d3 + 5eadc7e commit 367f308
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Harpoon.Registrations.EFStorage/WebHookReplayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public class WebHookReplayService<TContext>
{
private readonly TContext _context;
private readonly IWebHookSender _sender;
private readonly ISecretProtector _secretProtector;

/// <summary>Initializes a new instance of the <see cref="WebHookReplayService{TContext}"/> class.</summary>
public WebHookReplayService(TContext context, IWebHookSender sender)
public WebHookReplayService(TContext context, IWebHookSender sender, ISecretProtector secretProtector)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_sender = sender ?? throw new ArgumentNullException(nameof(sender));
_secretProtector = secretProtector ?? throw new ArgumentNullException(nameof(secretProtector));
}

/// <summary>
Expand All @@ -33,11 +35,22 @@ public async Task ReplayFailedNotification(DateTime start)
.Where(l => l.Error != null && l.CreatedAt >= start)
.Include(e => e.WebHookNotification)
.Include(e => e.WebHook)
.AsNoTracking()
.ToListAsync();

foreach (var fail in failedNotifications)
{
await _sender.SendAsync(new WebHookWorkItem(fail.WebHookNotificationId, fail.WebHookNotification, fail.WebHook), default);
var hasSuccesfulLogs = await _context.WebHookLogs
.Where(l => l.WebHookNotificationId == fail.WebHookNotificationId
&& l.WebHookId == fail.WebHookId
&& l.CreatedAt > fail.CreatedAt
&& l.Error == null).AnyAsync();

if (!hasSuccesfulLogs)
{
fail.WebHook.Secret = _secretProtector.Unprotect(fail.WebHook.ProtectedSecret);
await _sender.SendAsync(new WebHookWorkItem(fail.WebHookNotificationId, fail.WebHookNotification, fail.WebHook), default);
}
}
}
}
Expand Down

0 comments on commit 367f308

Please sign in to comment.