|
|
|
@ -11,6 +11,7 @@ namespace LINGYUN.Abp.Webhooks.BackgroundWorker |
|
|
|
public class WebhookSenderJob : AsyncBackgroundJob<WebhookSenderArgs>, ITransientDependency |
|
|
|
{ |
|
|
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|
|
|
private readonly IWebhookDefinitionManager _webhookDefinitionManager; |
|
|
|
private readonly IWebhookSubscriptionManager _webhookSubscriptionManager; |
|
|
|
private readonly IWebhookSendAttemptStore _webhookSendAttemptStore; |
|
|
|
private readonly IWebhookSender _webhookSender; |
|
|
|
@ -19,12 +20,14 @@ namespace LINGYUN.Abp.Webhooks.BackgroundWorker |
|
|
|
|
|
|
|
public WebhookSenderJob( |
|
|
|
IUnitOfWorkManager unitOfWorkManager, |
|
|
|
IWebhookDefinitionManager webhookDefinitionManager, |
|
|
|
IWebhookSubscriptionManager webhookSubscriptionManager, |
|
|
|
IWebhookSendAttemptStore webhookSendAttemptStore, |
|
|
|
IWebhookSender webhookSender, |
|
|
|
IOptions<AbpWebhooksOptions> options) |
|
|
|
{ |
|
|
|
_unitOfWorkManager = unitOfWorkManager; |
|
|
|
_webhookDefinitionManager = webhookDefinitionManager; |
|
|
|
_webhookSubscriptionManager = webhookSubscriptionManager; |
|
|
|
_webhookSendAttemptStore = webhookSendAttemptStore; |
|
|
|
_webhookSender = webhookSender; |
|
|
|
@ -33,11 +36,13 @@ namespace LINGYUN.Abp.Webhooks.BackgroundWorker |
|
|
|
|
|
|
|
public override async Task ExecuteAsync(WebhookSenderArgs args) |
|
|
|
{ |
|
|
|
if (args.TryOnce) |
|
|
|
var webhookDefinition = _webhookDefinitionManager.Get(args.WebhookName); |
|
|
|
|
|
|
|
if (webhookDefinition.TryOnce) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
await SendWebhook(args); |
|
|
|
await SendWebhook(args, webhookDefinition); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
@ -47,11 +52,11 @@ namespace LINGYUN.Abp.Webhooks.BackgroundWorker |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
await SendWebhook(args); |
|
|
|
await SendWebhook(args, webhookDefinition); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SendWebhook(WebhookSenderArgs args) |
|
|
|
private async Task SendWebhook(WebhookSenderArgs args, WebhookDefinition webhookDefinition) |
|
|
|
{ |
|
|
|
if (args.WebhookEventId == default) |
|
|
|
{ |
|
|
|
@ -63,7 +68,7 @@ namespace LINGYUN.Abp.Webhooks.BackgroundWorker |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (!args.TryOnce) |
|
|
|
if (!webhookDefinition.TryOnce) |
|
|
|
{ |
|
|
|
var sendAttemptCount = await _webhookSendAttemptStore.GetSendAttemptCountAsync( |
|
|
|
args.TenantId, |
|
|
|
@ -71,7 +76,8 @@ namespace LINGYUN.Abp.Webhooks.BackgroundWorker |
|
|
|
args.WebhookSubscriptionId |
|
|
|
); |
|
|
|
|
|
|
|
if (sendAttemptCount > _options.MaxSendAttemptCount) |
|
|
|
if ((webhookDefinition.MaxSendAttemptCount > 0 && sendAttemptCount > webhookDefinition.MaxSendAttemptCount) || |
|
|
|
sendAttemptCount > _options.MaxSendAttemptCount) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|