Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Umbraco.Infrastructure/BackgroundJobs/Jobs/WebhookFiring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs;
Expand All @@ -15,11 +14,11 @@ public class WebhookFiring : IRecurringBackgroundJob
{
private readonly ILogger<WebhookFiring> _logger;
private readonly IWebhookRequestService _webhookRequestService;
private readonly IJsonSerializer _jsonSerializer;
private readonly IWebhookLogFactory _webhookLogFactory;
private readonly IWebhookLogService _webhookLogService;
private readonly IWebhookService _webHookService;
private readonly ICoreScopeProvider _coreScopeProvider;
private readonly IHttpClientFactory _httpClientFactory;
private WebhookSettings _webhookSettings;

public TimeSpan Period => _webhookSettings.Period;
Expand All @@ -32,20 +31,20 @@ public event EventHandler PeriodChanged { add { } remove { } }
public WebhookFiring(
ILogger<WebhookFiring> logger,
IWebhookRequestService webhookRequestService,
IJsonSerializer jsonSerializer,
IWebhookLogFactory webhookLogFactory,
IWebhookLogService webhookLogService,
IWebhookService webHookService,
IOptionsMonitor<WebhookSettings> webhookSettings,
ICoreScopeProvider coreScopeProvider)
ICoreScopeProvider coreScopeProvider,
IHttpClientFactory httpClientFactory)
{
_logger = logger;
_webhookRequestService = webhookRequestService;
_jsonSerializer = jsonSerializer;
_webhookLogFactory = webhookLogFactory;
_webhookLogService = webhookLogService;
_webHookService = webHookService;
_coreScopeProvider = coreScopeProvider;
_httpClientFactory = httpClientFactory;
_webhookSettings = webhookSettings.CurrentValue;
webhookSettings.OnChange(x => _webhookSettings = x);
}
Expand Down Expand Up @@ -90,10 +89,11 @@ await Task.WhenAll(requests.Select(request =>

private async Task<HttpResponseMessage?> SendRequestAsync(IWebhook webhook, string eventName, string? serializedObject, int retryCount, CancellationToken cancellationToken)
{
using var httpClient = new HttpClient();
using HttpClient httpClient = _httpClientFactory.CreateClient();

var stringContent = new StringContent(serializedObject ?? string.Empty, Encoding.UTF8, MediaTypeNames.Application.Json);
stringContent.Headers.TryAddWithoutValidation("Umb-Webhook-Event", eventName);
stringContent.Headers.TryAddWithoutValidation("Umb-Webhook-RetryCount", retryCount.ToString());

foreach (KeyValuePair<string, string> header in webhook.Headers)
{
Expand All @@ -107,7 +107,7 @@ await Task.WhenAll(requests.Select(request =>
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while sending webhook request for webhook {WebhookKey}.", webhook);
_logger.LogError(ex, "Error while sending webhook request for webhook {WebhookKey}.", webhook.Key);
}

var webhookResponseModel = new WebhookResponseModel
Expand Down