Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/EventStore.ClusterNode/ClusterVNodeHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace EventStore.ClusterNode;
public class ClusterVNodeHostedService : IHostedService, IDisposable
{
private static readonly ILogger Log = Serilog.Log.ForContext<ClusterVNodeHostedService>();
private static readonly TimeProvider Time = TimeProvider.System;

private readonly ClusterVNodeOptions _options;
private readonly ExclusiveDbLock _dbLock;
Expand Down Expand Up @@ -389,11 +390,42 @@ IEnumerable<IMD5ProviderFactory> GetMD5ProviderFactories()
}
}

public Task StartAsync(CancellationToken cancellationToken) =>
_options.Application.WhatIf ? Task.CompletedTask : Node.StartAsync(false, cancellationToken);
public async Task StartAsync(CancellationToken cancellationToken)
{
if (_options.Application.WhatIf)
{
return;
}

var startedAt = Time.GetTimestamp();
Log.Information("Starting cluster node.");
try
{
await Node.StartAsync(false, cancellationToken);
Log.Information("Cluster node started in {Elapsed}.", Time.GetElapsedTime(startedAt));
}
catch (Exception exception)
{
Log.Error(exception, "Cluster node failed to start after {Elapsed}.", Time.GetElapsedTime(startedAt));
throw;
}
}

public Task StopAsync(CancellationToken cancellationToken) =>
Node.StopAsync(cancellationToken: cancellationToken);
public async Task StopAsync(CancellationToken cancellationToken)
{
var startedAt = Time.GetTimestamp();
Log.Information("Stopping cluster node.");
try
{
await Node.StopAsync(cancellationToken: cancellationToken);
Log.Information("Cluster node stopped in {Elapsed}.", Time.GetElapsedTime(startedAt));
}
catch (Exception exception)
{
Log.Error(exception, "Cluster node failed to stop after {Elapsed}.", Time.GetElapsedTime(startedAt));
throw;
}
}

public void Dispose()
{
Expand Down
Loading