From 4506036abf3e3b348a53cb58b2dc03f78cb12700 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sun, 25 Aug 2024 17:12:26 -0500 Subject: [PATCH] feat: make refresh interval configurable --- src/SanctionsSearch.Worker/Options/DbOptions.cs | 1 + src/SanctionsSearch.Worker/Workers/DatabaseWorker.cs | 7 +++++-- src/SanctionsSearch.Worker/appsettings.Example.json | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) 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