1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-14 14:17:35 -05:00

Run formatting (#2230)

This commit is contained in:
Justin Baur
2022-08-29 16:06:55 -04:00
committed by GitHub
parent 9b7aef0763
commit 7f5f010e1e
1205 changed files with 73813 additions and 75022 deletions

View File

@ -1,57 +1,56 @@
using Bit.Core.Settings;
using Microsoft.AspNetCore.SignalR;
namespace Bit.Notifications
namespace Bit.Notifications;
public class HeartbeatHostedService : IHostedService, IDisposable
{
public class HeartbeatHostedService : IHostedService, IDisposable
private readonly ILogger _logger;
private readonly IHubContext<NotificationsHub> _hubContext;
private readonly GlobalSettings _globalSettings;
private Task _executingTask;
private CancellationTokenSource _cts;
public HeartbeatHostedService(
ILogger<AzureQueueHostedService> logger,
IHubContext<NotificationsHub> hubContext,
GlobalSettings globalSettings)
{
private readonly ILogger _logger;
private readonly IHubContext<NotificationsHub> _hubContext;
private readonly GlobalSettings _globalSettings;
_logger = logger;
_hubContext = hubContext;
_globalSettings = globalSettings;
}
private Task _executingTask;
private CancellationTokenSource _cts;
public Task StartAsync(CancellationToken cancellationToken)
{
_cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
_executingTask = ExecuteAsync(_cts.Token);
return _executingTask.IsCompleted ? _executingTask : Task.CompletedTask;
}
public HeartbeatHostedService(
ILogger<AzureQueueHostedService> logger,
IHubContext<NotificationsHub> hubContext,
GlobalSettings globalSettings)
public async Task StopAsync(CancellationToken cancellationToken)
{
if (_executingTask == null)
{
_logger = logger;
_hubContext = hubContext;
_globalSettings = globalSettings;
return;
}
_logger.LogWarning("Stopping service.");
_cts.Cancel();
await Task.WhenAny(_executingTask, Task.Delay(-1, cancellationToken));
cancellationToken.ThrowIfCancellationRequested();
}
public Task StartAsync(CancellationToken cancellationToken)
public void Dispose()
{ }
private async Task ExecuteAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
_cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
_executingTask = ExecuteAsync(_cts.Token);
return _executingTask.IsCompleted ? _executingTask : Task.CompletedTask;
}
public async Task StopAsync(CancellationToken cancellationToken)
{
if (_executingTask == null)
{
return;
}
_logger.LogWarning("Stopping service.");
_cts.Cancel();
await Task.WhenAny(_executingTask, Task.Delay(-1, cancellationToken));
cancellationToken.ThrowIfCancellationRequested();
}
public void Dispose()
{ }
private async Task ExecuteAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
await _hubContext.Clients.All.SendAsync("Heartbeat");
await Task.Delay(120000);
}
_logger.LogWarning("Done with heartbeat.");
await _hubContext.Clients.All.SendAsync("Heartbeat");
await Task.Delay(120000);
}
_logger.LogWarning("Done with heartbeat.");
}
}