2021-07-08 17:32:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2021-07-15 15:45:17 +00:00
|
|
|
|
using ASC.Common.Caching;
|
2021-07-08 17:32:59 +00:00
|
|
|
|
using ASC.Common.Logging;
|
|
|
|
|
using ASC.Core;
|
2021-07-15 15:45:17 +00:00
|
|
|
|
using ASC.Web.Webhooks;
|
2021-07-08 17:32:59 +00:00
|
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
|
|
namespace ASC.Webhooks
|
|
|
|
|
{
|
|
|
|
|
public class WebhookHostedService : BackgroundService
|
|
|
|
|
{
|
|
|
|
|
private ILog Log { get; }
|
|
|
|
|
private DbWorker DbWorker { get; }
|
|
|
|
|
private TenantManager TenantManager { get; }
|
|
|
|
|
private WebhookSender WebhookSender { get; }
|
|
|
|
|
|
2021-07-15 15:45:17 +00:00
|
|
|
|
private ICacheNotify<WebhookRequest> CacheNotify { get; }
|
|
|
|
|
|
2021-07-08 17:32:59 +00:00
|
|
|
|
public WebhookHostedService(IOptionsMonitor<ILog> option,
|
|
|
|
|
DbWorker dbWorker,
|
|
|
|
|
TenantManager tenantManager,
|
2021-07-15 15:45:17 +00:00
|
|
|
|
WebhookSender webhookSender,
|
|
|
|
|
ICacheNotify<WebhookRequest> cacheNotify)
|
2021-07-08 17:32:59 +00:00
|
|
|
|
{
|
|
|
|
|
Log = option.Get("ASC.Webhooks");
|
|
|
|
|
DbWorker = dbWorker;
|
|
|
|
|
TenantManager = tenantManager;
|
|
|
|
|
WebhookSender = webhookSender;
|
2021-07-15 15:45:17 +00:00
|
|
|
|
CacheNotify = cacheNotify;
|
2021-07-08 17:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
|
|
{
|
|
|
|
|
Log.Debug(
|
2021-07-15 15:45:17 +00:00
|
|
|
|
$"WebhookHostedService is starting.");
|
2021-07-08 17:32:59 +00:00
|
|
|
|
|
|
|
|
|
stoppingToken.Register(() =>
|
|
|
|
|
Log.Debug($"WebhookHostedService is stopping."));
|
|
|
|
|
|
2021-07-15 15:45:17 +00:00
|
|
|
|
CacheNotify.Subscribe(BackgroundProcessing, CacheNotifyAction.Update);
|
2021-07-08 17:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-15 15:45:17 +00:00
|
|
|
|
public void Stop()
|
2021-07-08 17:32:59 +00:00
|
|
|
|
{
|
2021-07-15 15:45:17 +00:00
|
|
|
|
CacheNotify.Unsubscribe(CacheNotifyAction.Update);
|
|
|
|
|
}
|
2021-07-08 17:32:59 +00:00
|
|
|
|
|
2021-07-15 15:45:17 +00:00
|
|
|
|
private void BackgroundProcessing(WebhookRequest request)// горизонтальная, вертикальная кластеризация, добавление в очередь из паблишера
|
|
|
|
|
{
|
|
|
|
|
WebhookSender.Send(request);
|
2021-07-08 17:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|