DocSpace-buildtools/common/services/ASC.Webhooks.Service/Services/BuildQueueService.cs

30 lines
852 B
C#
Raw Normal View History

2022-02-10 14:03:44 +00:00
namespace ASC.Webhooks.Service.Services;
[Singletone]
public class BuildQueueService : BackgroundService
2022-02-02 14:23:15 +00:00
{
2022-02-17 21:43:30 +00:00
internal readonly ConcurrentQueue<WebhookRequest> Queue;
private readonly ICacheNotify<WebhookRequest> _webhookNotify;
2022-02-11 14:39:34 +00:00
public BuildQueueService(ICacheNotify<WebhookRequest> webhookNotify)
{
_webhookNotify = webhookNotify;
2022-02-17 21:43:30 +00:00
Queue = new ConcurrentQueue<WebhookRequest>();
}
2022-02-11 14:33:00 +00:00
public void BuildWebhooksQueue(WebhookRequest request)
{
2022-02-17 21:43:30 +00:00
Queue.Enqueue(request);
2022-02-11 14:33:00 +00:00
}
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
_webhookNotify.Subscribe(BuildWebhooksQueue, CacheNotifyAction.Update);
stoppingToken.Register(() =>
{
_webhookNotify.Unsubscribe(CacheNotifyAction.Update);
});
return Task.CompletedTask;
}
2022-02-10 14:03:44 +00:00
}