DocSpace-buildtools/common/services/ASC.Webhooks.Service/Services/BuildQueueService.cs
2022-02-10 17:03:44 +03:00

31 lines
885 B
C#

namespace ASC.Webhooks.Service.Services;
[Singletone]
public class BuildQueueService : IHostedService
{
internal ConcurrentQueue<WebhookRequest> Queue { get; }
private readonly ICacheNotify<WebhookRequest> _webhookNotify;
public BuildQueueService(ICacheNotify<WebhookRequest> webhookNotify)
{
_webhookNotify = webhookNotify;
Queue = new ConcurrentQueue<WebhookRequest>();
}
public Task StartAsync(CancellationToken cancellationToken)
{
_webhookNotify.Subscribe(BuildWebhooksQueue, CacheNotifyAction.Update);
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
_webhookNotify.Unsubscribe(CacheNotifyAction.Update);
return Task.CompletedTask;
}
public void BuildWebhooksQueue(WebhookRequest request)
{
Queue.Enqueue(request);
}
}