diff --git a/src/SanctionsSearch.Worker/Options/DbOptions.cs b/src/SanctionsSearch.Worker/Options/DbOptions.cs index 1d6fbea..a49b8bf 100644 --- a/src/SanctionsSearch.Worker/Options/DbOptions.cs +++ b/src/SanctionsSearch.Worker/Options/DbOptions.cs @@ -3,4 +3,5 @@ namespace SanctionsSearch.Worker.Options; class DbOptions { public string DatabaseName { get; set; } = string.Empty; + public int RefreshIntervalInHours { get; set; } = 1; } \ No newline at end of file diff --git a/src/SanctionsSearch.Worker/Workers/DatabaseWorker.cs b/src/SanctionsSearch.Worker/Workers/DatabaseWorker.cs index 246c07b..473cb93 100644 --- a/src/SanctionsSearch.Worker/Workers/DatabaseWorker.cs +++ b/src/SanctionsSearch.Worker/Workers/DatabaseWorker.cs @@ -17,11 +17,14 @@ public class DatabaseWorker( await UpdateDatabase(); + using var scope = _serviceScopeFactory.CreateScope(); + var dbOptions = scope.ServiceProvider.GetRequiredService(); + _timer = _timeProvider.CreateTimer( callback: async _ => await UpdateDatabase(), state: null, - dueTime: TimeSpan.FromHours(1), - period: TimeSpan.FromHours(1) + dueTime: TimeSpan.FromHours(dbOptions.RefreshIntervalInHours), + period: TimeSpan.FromHours(dbOptions.RefreshIntervalInHours) ); } diff --git a/src/SanctionsSearch.Worker/appsettings.Example.json b/src/SanctionsSearch.Worker/appsettings.Example.json index 5e8a9c5..ed4fffe 100644 --- a/src/SanctionsSearch.Worker/appsettings.Example.json +++ b/src/SanctionsSearch.Worker/appsettings.Example.json @@ -17,6 +17,7 @@ "ConCommentsFileName": "CONS_COMMENTS.CSV" }, "DbOptions": { - "DatabaseName": "SanctionsSearch.example.db" + "DatabaseName": "SanctionsSearch.example.db", + "RefreshIntervalInHours": 1 } } \ No newline at end of file