コード例 #1
0
        /// <inheritdoc />
        public async Task ProcessAsync(IWebHookNotification notification, CancellationToken cancellationToken)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var webHooks = await _webHookStore.GetApplicableWebHooksAsync(notification, cancellationToken);

            var id = await LogAsync(notification, webHooks, cancellationToken);

            var tasks = webHooks.Select(w => new { Task = _webHookSender.SendAsync(new WebHookWorkItem(id, notification, w), cancellationToken), Name = w.Callback });

            try
            {
                await Task.WhenAll(tasks.Select(t => t.Task));
            }
            catch (TaskCanceledException)
            {
                var canceledWebHooks = tasks.Where(a => !a.Task.IsCompleted).Select(a => a.Name);
                _logger.LogError("The following urls have not been called due to a task cancellation: " + string.Join(Environment.NewLine, canceledWebHooks));
            }
            catch
            {
                var canceledWebHooks = tasks.Where(a => !a.Task.IsCompleted).Select(a => a.Name);
                _logger.LogError("The following urls have not been called due to an error: " + string.Join(Environment.NewLine, canceledWebHooks));
            }
        }
コード例 #2
0
        /// <inheritdoc />
        public async Task ProcessAsync(IWebHookNotification notification, CancellationToken cancellationToken)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var webHooks = await _webHookStore.GetApplicableWebHooksAsync(notification, cancellationToken);

            await Task.WhenAll(webHooks.Select(w => _webHookSender.SendAsync(new WebHookWorkItem(notification, w), cancellationToken)));
        }
コード例 #3
0
        /// <summary>
        /// Replays every failed notification
        /// </summary>
        /// <param name="start"></param>
        /// <returns></returns>
        public async Task ReplayFailedNotification(DateTime start)
        {
            var failedNotifications = await _context.WebHookLogs
                                      .Where(l => l.Error != null && l.CreatedAt >= start)
                                      .Include(e => e.WebHookNotification)
                                      .Include(e => e.WebHook)
                                      .AsNoTracking()
                                      .ToListAsync();

            foreach (var fail in failedNotifications)
            {
                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);
                }
            }
        }