2021-07-31 17:12:41 +00:00
|
|
|
|
using System.Threading;
|
2021-07-08 17:32:59 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2021-07-26 17:03:55 +00:00
|
|
|
|
using ASC.Common;
|
2021-07-08 17:32:59 +00:00
|
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
2021-08-26 18:43:41 +00:00
|
|
|
|
namespace ASC.Webhooks.Service
|
2021-07-08 17:32:59 +00:00
|
|
|
|
{
|
2021-07-26 17:03:55 +00:00
|
|
|
|
[Singletone]
|
|
|
|
|
public class WebhookHostedService : IHostedService
|
2021-07-08 17:32:59 +00:00
|
|
|
|
{
|
2021-07-26 17:03:55 +00:00
|
|
|
|
private WorkerService workerService;
|
2021-08-03 16:26:28 +00:00
|
|
|
|
private BuildQueueService buildQueueService;
|
2021-07-08 17:32:59 +00:00
|
|
|
|
|
2021-08-03 16:26:28 +00:00
|
|
|
|
public WebhookHostedService(WorkerService workerService,
|
|
|
|
|
BuildQueueService buildQueueService)
|
2021-07-08 17:32:59 +00:00
|
|
|
|
{
|
2021-08-03 16:26:28 +00:00
|
|
|
|
this.workerService = workerService;
|
|
|
|
|
this.buildQueueService = buildQueueService;
|
2021-07-08 17:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 17:03:55 +00:00
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
|
|
|
{
|
2021-08-03 16:26:28 +00:00
|
|
|
|
workerService.Start(cancellationToken);
|
|
|
|
|
buildQueueService.Start();
|
2021-07-08 17:32:59 +00:00
|
|
|
|
|
2021-07-26 17:03:55 +00:00
|
|
|
|
return Task.CompletedTask;
|
2021-07-08 17:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 17:03:55 +00:00
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
2021-07-08 17:32:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
2021-07-26 17:03:55 +00:00
|
|
|
|
if (workerService != null)
|
|
|
|
|
{
|
|
|
|
|
workerService.Stop();
|
|
|
|
|
workerService = null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-03 16:26:28 +00:00
|
|
|
|
if (buildQueueService != null)
|
2021-07-26 17:03:55 +00:00
|
|
|
|
{
|
2021-08-03 16:26:28 +00:00
|
|
|
|
buildQueueService.Stop();
|
2021-07-26 17:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
2021-07-08 17:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|