Skip to content

Commit

Permalink
Fix startup
Browse files Browse the repository at this point in the history
  • Loading branch information
rs22 committed Dec 18, 2023
1 parent dc8d070 commit 099cf68
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/Point/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ public partial class Point : BackgroundService, IPoint

private readonly ILogger<Point> _logger;
private readonly IConnectionProvider _connectionProvider;
private readonly Func<Task> _simulateTimeout;
private readonly PointConfiguration _config;

public Point(ILogger<Point> logger, IConfiguration configuration, IPointToInterlockingConnection connection, IConnectionProvider connectionProvider, Func<Task> simulateTimeout, IHubContext<StatusHub> statusHub)
public Point(ILogger<Point> logger, IConfiguration configuration, IPointToInterlockingConnection connection, IConnectionProvider connectionProvider, IHubContext<StatusHub> statusHub)
{
Connection = connection;
_connectionProvider = connectionProvider;
_logger = logger;
_simulateTimeout = simulateTimeout;

_config = configuration.GetSection("PointSettings").Get<PointConfiguration>() ?? throw new Exception("No configuration provided");
AllPointMachinesCrucial = _config.AllPointMachinesCrucial;
Expand Down Expand Up @@ -338,7 +336,6 @@ private async Task HandleCommandedPointPosition(GenericPointPosition commandedPo
{
_logger.LogInformation("Timeout");
await Connection.SendTimeoutMessage();
await _simulateTimeout();
}
else
{
Expand Down
8 changes: 2 additions & 6 deletions src/Point/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ public void ConfigureServices(IServiceCollection services)

try
{
services.AddSingleton(x =>
{
var simulateTimout = async () => await Task.Delay(new Random().Next(1, 5) * 1000);
return ActivatorUtilities.CreateInstance<Point>(x, simulateTimout);
});
services.AddSingleton(x => x.GetRequiredService<Point>());
services.AddSingleton<Point>();
}
catch (Exception e)
{
Console.WriteLine($"Usage: --PointSettings:LocalId=<> --PointSettings:LocalRastaId=<> --PointSettings:RemoteId=<> --PointSettings:RemoteEndpoint=<>. {e.Message}");
Environment.Exit(1);
}

services.AddSingleton<IPoint>(x => x.GetRequiredService<Point>());
_ = services.AddHostedService(provider => provider.GetRequiredService<Point>());
}

Expand Down

0 comments on commit 099cf68

Please sign in to comment.