Skip to content

Commit

Permalink
Fixes missed _periodSec variable (#4666)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankowitz authored Oct 9, 2024
1 parent 07290d6 commit e9a0162
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions src/Microsoft.Health.Fhir.SqlServer/Features/Watchdogs/Watchdog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ internal abstract class Watchdog<T>
private readonly ISqlRetryService _sqlRetryService;
private readonly ILogger<T> _logger;
private readonly WatchdogLease<T> _watchdogLease;
private double _periodSec;
private double _leasePeriodSec;
private readonly FhirTimer _fhirTimer;

protected Watchdog(ISqlRetryService sqlRetryService, ILogger<T> logger)
Expand Down Expand Up @@ -60,11 +58,11 @@ public async Task ExecuteAsync(CancellationToken cancellationToken)
{
_logger.LogInformation($"{Name}.ExecuteAsync: starting...");

await InitParamsAsync(PeriodSec, LeasePeriodSec);
await InitParamsAsync();

await Task.WhenAll(
_fhirTimer.ExecuteAsync(_periodSec, OnNextTickAsync, cancellationToken),
_watchdogLease.ExecuteAsync(AllowRebalance, _leasePeriodSec, cancellationToken));
_fhirTimer.ExecuteAsync(PeriodSec, OnNextTickAsync, cancellationToken),
_watchdogLease.ExecuteAsync(AllowRebalance, LeasePeriodSec, cancellationToken));

_logger.LogInformation($"{Name}.ExecuteAsync: completed.");
}
Expand All @@ -85,7 +83,7 @@ private async Task OnNextTickAsync(CancellationToken cancellationToken)
}
}

private async Task InitParamsAsync(double periodSec, double leasePeriodSec) // No CancellationToken is passed since we shouldn't cancel initialization.
private async Task InitParamsAsync() // No CancellationToken is passed since we shouldn't cancel initialization.
{
using (_logger.BeginTimedScope($"{Name}.InitParamsAsync"))
{
Expand All @@ -98,13 +96,13 @@ INSERT INTO dbo.Parameters (Id,Number) SELECT @PeriodSecId, @PeriodSec
INSERT INTO dbo.Parameters (Id,Number) SELECT @LeasePeriodSecId, @LeasePeriodSec
");
cmd.Parameters.AddWithValue("@PeriodSecId", PeriodSecId);
cmd.Parameters.AddWithValue("@PeriodSec", periodSec);
cmd.Parameters.AddWithValue("@PeriodSec", PeriodSec);
cmd.Parameters.AddWithValue("@LeasePeriodSecId", LeasePeriodSecId);
cmd.Parameters.AddWithValue("@LeasePeriodSec", leasePeriodSec);
cmd.Parameters.AddWithValue("@LeasePeriodSec", LeasePeriodSec);
await cmd.ExecuteNonQueryAsync(_sqlRetryService, _logger, CancellationToken.None);

_periodSec = await GetPeriodAsync(CancellationToken.None);
_leasePeriodSec = await GetLeasePeriodAsync(CancellationToken.None);
PeriodSec = await GetPeriodAsync(CancellationToken.None);
LeasePeriodSec = await GetLeasePeriodAsync(CancellationToken.None);

await InitAdditionalParamsAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ FOR INSERT

Task wdTask = wd.ExecuteAsync(cts.Token);
DateTime startTime = DateTime.UtcNow;
while (!wd.IsLeaseHolder && (DateTime.UtcNow - startTime).TotalSeconds < 10)
while (!wd.IsLeaseHolder && (DateTime.UtcNow - startTime).TotalSeconds < 20)
{
await Task.Delay(TimeSpan.FromSeconds(0.2), cts.Token);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ public async Task AdvanceVisibility()

Task wdTask = wd.ExecuteAsync(cts.Token);
var startTime = DateTime.UtcNow;
while (!wd.IsLeaseHolder && (DateTime.UtcNow - startTime).TotalSeconds < 10)
while (!wd.IsLeaseHolder && (DateTime.UtcNow - startTime).TotalSeconds < 20)
{
await Task.Delay(TimeSpan.FromSeconds(0.2), cts.Token);
}
Expand Down

0 comments on commit e9a0162

Please sign in to comment.