feat: make refresh interval configurable

This commit is contained in:
Stevan Freeborn
2024-08-25 17:12:26 -05:00
parent c35bcdad90
commit 4506036abf
3 changed files with 8 additions and 3 deletions
@@ -3,4 +3,5 @@ namespace SanctionsSearch.Worker.Options;
class DbOptions class DbOptions
{ {
public string DatabaseName { get; set; } = string.Empty; public string DatabaseName { get; set; } = string.Empty;
public int RefreshIntervalInHours { get; set; } = 1;
} }
@@ -17,11 +17,14 @@ public class DatabaseWorker(
await UpdateDatabase(); await UpdateDatabase();
using var scope = _serviceScopeFactory.CreateScope();
var dbOptions = scope.ServiceProvider.GetRequiredService<DbOptions>();
_timer = _timeProvider.CreateTimer( _timer = _timeProvider.CreateTimer(
callback: async _ => await UpdateDatabase(), callback: async _ => await UpdateDatabase(),
state: null, state: null,
dueTime: TimeSpan.FromHours(1), dueTime: TimeSpan.FromHours(dbOptions.RefreshIntervalInHours),
period: TimeSpan.FromHours(1) period: TimeSpan.FromHours(dbOptions.RefreshIntervalInHours)
); );
} }
@@ -17,6 +17,7 @@
"ConCommentsFileName": "CONS_COMMENTS.CSV" "ConCommentsFileName": "CONS_COMMENTS.CSV"
}, },
"DbOptions": { "DbOptions": {
"DatabaseName": "SanctionsSearch.example.db" "DatabaseName": "SanctionsSearch.example.db",
"RefreshIntervalInHours": 1
} }
} }