-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from moreal/PDX-369
PDX-395: Refactor initialization process
- Loading branch information
Showing
13 changed files
with
335 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using NineChroniclesUtilBackend.Store.Scrapper; | ||
using NineChroniclesUtilBackend.Store.Client; | ||
using NineChroniclesUtilBackend.Store.Services; | ||
|
||
namespace NineChroniclesUtilBackend.Store; | ||
|
||
public class Initializer : BackgroundService | ||
{ | ||
private readonly MongoDbStore _store; | ||
private readonly ArenaScrapper _scrapper; | ||
private readonly ILogger<Initializer> _logger; | ||
private readonly IStateService _stateService; | ||
|
||
public Initializer( | ||
ILogger<Initializer> logger, | ||
ILogger<ArenaScrapper> scrapperLogger, | ||
IStateService stateService, | ||
MongoDbStore store, | ||
EmptyChronicleClient client) | ||
{ | ||
_logger = logger; | ||
_stateService = stateService; | ||
_store = store; | ||
_scrapper = new ArenaScrapper(scrapperLogger, _stateService, client, _store); | ||
} | ||
|
||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
var started = DateTime.UtcNow; | ||
|
||
if (!await _store.IsInitialized()) | ||
{ | ||
await _scrapper.ExecuteAsync(); | ||
} | ||
|
||
var totalElapsedMinutes = DateTime.UtcNow.Subtract(started).Minutes; | ||
_logger.LogInformation($"Finished Initializer background service. Elapsed {totalElapsedMinutes} minutes."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.