Skip to content

Commit

Permalink
Cleanup of staled rounds (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Sep 7, 2024
1 parent bbbaca1 commit fa13d78
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
3 changes: 1 addition & 2 deletions dkgNodesTests/RoundStatus.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ public void TestNextStatus()
[Test]
public void TestCancelStatus()
{
RoundStatus roundStatus = RoundStatusConstants.Started;
Assert.That(roundStatus.CancelStatus(), Is.EqualTo(RoundStatusConstants.Cancelled));
Assert.That(RoundStatus.CancelStatus(), Is.EqualTo(RoundStatusConstants.Cancelled));
}

[Test]
Expand Down
22 changes: 22 additions & 0 deletions dkgServiceNode/Controllers/OpsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public async Task<ActionResult<StatusResponse>> RegisterNode(Node node)
Stopwatch stopwatch = new();
stopwatch.Start();

await UpdateRunningRoundsIfNeeded();

ActionResult<StatusResponse> res;
bool verified = false;

Expand Down Expand Up @@ -576,5 +578,25 @@ internal async Task UpdateRoundState(Round round)
}
}

private static DateTime lastUpdateRunningRoundsTime = DateTime.MinValue;
private static readonly TimeSpan updateRunningRoundsInterval = TimeSpan.FromSeconds(120);

internal async Task UpdateRunningRounds()
{
var rounds = dkgContext.GetAllRounds().Where(r => RoundStatus.IsRunning(r.Status));
foreach (var round in rounds)
{
await UpdateRoundState(round);
}
}
private async Task UpdateRunningRoundsIfNeeded()
{
if (DateTime.Now - lastUpdateRunningRoundsTime >= updateRunningRoundsInterval)
{
await UpdateRunningRounds();
lastUpdateRunningRoundsTime = DateTime.Now;
}
}

}
}
3 changes: 0 additions & 3 deletions dkgServiceNode/Controllers/RoundsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
using dkgServiceNode.Services.RoundRunner;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Xml.Linq;
using Microsoft.Extensions.DependencyInjection;
using dkgServiceNode.Services.Cache;

namespace dkgServiceNode.Controllers
Expand Down
1 change: 1 addition & 0 deletions dkgServiceNode/Data/DbEnsure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public static void Ensure(string connectionString)
Ensure_0_8_0(connection);
EnsureVersion("0.12.1", sqlScript_0_12_1, connection);
PuVersionUpdate("0.12.4", connection);
PuVersionUpdate("0.12.5", connection);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dkgServiceNode/Models/Round.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public RoundStatus NextStatus
[NotMapped]
public RoundStatus CancelStatus
{
get { return Status.CancelStatus(); }
get { return RoundStatus.CancelStatus(); }

Check failure on line 114 in dkgServiceNode/Models/Round.cs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

An object reference is required for the non-static field, method, or property 'RoundStatus.CancelStatus()'

Check failure on line 114 in dkgServiceNode/Models/Round.cs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

An object reference is required for the non-static field, method, or property 'RoundStatus.CancelStatus()'

Check failure on line 114 in dkgServiceNode/Models/Round.cs

View workflow job for this annotation

GitHub Actions / Test on windows-latest

An object reference is required for the non-static field, method, or property 'RoundStatus.CancelStatus()'

Check failure on line 114 in dkgServiceNode/Models/Round.cs

View workflow job for this annotation

GitHub Actions / Test on windows-latest

An object reference is required for the non-static field, method, or property 'RoundStatus.CancelStatus()'

Check failure on line 114 in dkgServiceNode/Models/Round.cs

View workflow job for this annotation

GitHub Actions / Test on macos-latest

An object reference is required for the non-static field, method, or property 'RoundStatus.CancelStatus()'

Check failure on line 114 in dkgServiceNode/Models/Round.cs

View workflow job for this annotation

GitHub Actions / Test on macos-latest

An object reference is required for the non-static field, method, or property 'RoundStatus.CancelStatus()'
}

[JsonIgnore]
Expand Down

0 comments on commit fa13d78

Please sign in to comment.