feat: make refresh interval configurable
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user