feat(phase-4): application layer + background workers — 202/202 tests green

Use cases (Marathon.Application/UseCases/):
- PullUpcomingEventsUseCase: scrape + persist new events + capture pre-match snapshots
- PullLiveOddsUseCase: refresh live snapshots for all stored events
- PullResultsUseCase: Phase 4 scaffold; delegates to ScrapeResultsAsync (Phase 3 no-op);
  Phase 8 will replace with watch-list polling
- ExportToExcelUseCase: resolves export dir from StorageOptions, delegates to IExcelExporter

ApplicationModule.AddMarathonApplication(IServiceCollection) — no IConfiguration needed.

Background workers (Marathon.Infrastructure/Workers/):
- UpcomingEventsPoller: Cronos 6-field cron schedule (default every 6 h)
- LiveOddsPoller: fixed interval (WorkerOptions.LivePollIntervalSeconds, default 30 s)
- ResultsWatchListPoller: scaffold, disabled by default (WorkerOptions.ResultsPollerEnabled=false)
All three: exception-swallowing, cancellation-aware, scoped DI via CreateAsyncScope().

InfrastructureModule.AddMarathonInfrastructure(IServiceCollection, IConfiguration):
- Composes AddMarathonPersistence + AddMarathonScraping + WorkerOptions + 3 hosted services

App.xaml.cs: replace reflection-based TryAddApplicationAndInfrastructure with direct
AddMarathonApplication() + AddMarathonInfrastructure(config) calls.

Resolved Phase 3 TODO: bind Sports:Basketball:QuarterMode from config in ScrapingModule.

appsettings.json: add Workers.LivePollIntervalSeconds, ResultsPollIntervalSeconds,
ResultsPollerEnabled; add Sports.Basketball.QuarterMode.

Settings.razor + WorkerOptions (UI) + SharedResource.*.resx: surface new Workers fields.

Tests: +14 Application use-case tests, +3 Infrastructure worker tests (185 → 202 total).
This commit is contained in:
2026-05-05 12:28:15 +03:00
parent c4d87b59d6
commit 2acbaa5b77
31 changed files with 1719 additions and 94 deletions
+15 -3
View File
@@ -89,6 +89,15 @@
<Field Label="@L["Settings.Workers.LivePollerEnabled"]">
<MudSwitch T="bool" @bind-Value="_workers.LivePollerEnabled" Color="Color.Primary" />
</Field>
<Field Label="@L["Settings.Workers.LivePollIntervalSeconds"]" Hint="@L["Settings.Workers.LivePollIntervalSeconds.Hint"]">
<MudNumericField T="int" @bind-Value="_workers.LivePollIntervalSeconds" Min="5" Max="3600" Variant="Variant.Outlined" />
</Field>
<Field Label="@L["Settings.Workers.ResultsPollerEnabled"]" Hint="@L["Settings.Workers.ResultsPollerEnabled.Hint"]">
<MudSwitch T="bool" @bind-Value="_workers.ResultsPollerEnabled" Color="Color.Primary" />
</Field>
<Field Label="@L["Settings.Workers.ResultsPollIntervalSeconds"]">
<MudNumericField T="int" @bind-Value="_workers.ResultsPollIntervalSeconds" Min="60" Max="7200" Variant="Variant.Outlined" />
</Field>
<SectionFooter OnSave="@(() => SaveSectionAsync(WorkerOptions.SectionName, _workers))" />
</div>
@@ -182,9 +191,12 @@
_workers = new WorkerOptions
{
UpcomingScheduleCron = WorkerOpts.CurrentValue.UpcomingScheduleCron,
LivePollerEnabled = WorkerOpts.CurrentValue.LivePollerEnabled,
UpcomingPollerEnabled = WorkerOpts.CurrentValue.UpcomingPollerEnabled,
UpcomingScheduleCron = WorkerOpts.CurrentValue.UpcomingScheduleCron,
LivePollerEnabled = WorkerOpts.CurrentValue.LivePollerEnabled,
UpcomingPollerEnabled = WorkerOpts.CurrentValue.UpcomingPollerEnabled,
LivePollIntervalSeconds = WorkerOpts.CurrentValue.LivePollIntervalSeconds,
ResultsPollerEnabled = WorkerOpts.CurrentValue.ResultsPollerEnabled,
ResultsPollIntervalSeconds = WorkerOpts.CurrentValue.ResultsPollIntervalSeconds,
};
_storage = new StorageOptions
@@ -114,6 +114,11 @@
<data name="Settings.Workers.UpcomingScheduleCron.Hint"><value>Standard cron. Defaults to every 5 minutes.</value></data>
<data name="Settings.Workers.LivePollerEnabled"><value>Live poller enabled</value></data>
<data name="Settings.Workers.UpcomingPollerEnabled"><value>Schedule poller enabled</value></data>
<data name="Settings.Workers.LivePollIntervalSeconds"><value>Live poll interval (sec)</value></data>
<data name="Settings.Workers.LivePollIntervalSeconds.Hint"><value>Delay between live-odds polling cycles. Default 30 s.</value></data>
<data name="Settings.Workers.ResultsPollerEnabled"><value>Results poller enabled</value></data>
<data name="Settings.Workers.ResultsPollerEnabled.Hint"><value>Disabled until Phase 8. Enable only after match-complete polling is implemented.</value></data>
<data name="Settings.Workers.ResultsPollIntervalSeconds"><value>Results poll interval (sec)</value></data>
<data name="Settings.Storage.DatabasePath"><value>SQLite path</value></data>
<data name="Settings.Storage.ExportDirectory"><value>Export directory</value></data>
@@ -120,6 +120,11 @@
<data name="Settings.Workers.UpcomingScheduleCron.Hint"><value>Стандартный cron. По умолчанию каждые 5 минут.</value></data>
<data name="Settings.Workers.LivePollerEnabled"><value>Лайв-сборщик включён</value></data>
<data name="Settings.Workers.UpcomingPollerEnabled"><value>Сборщик расписания включён</value></data>
<data name="Settings.Workers.LivePollIntervalSeconds"><value>Интервал лайв-опроса (сек)</value></data>
<data name="Settings.Workers.LivePollIntervalSeconds.Hint"><value>Пауза между циклами сбора лайв-котировок. По умолчанию 30 с.</value></data>
<data name="Settings.Workers.ResultsPollerEnabled"><value>Сборщик результатов включён</value></data>
<data name="Settings.Workers.ResultsPollerEnabled.Hint"><value>Отключён до Phase 8. Включите только после реализации опроса match-complete.</value></data>
<data name="Settings.Workers.ResultsPollIntervalSeconds"><value>Интервал сборщика результатов (сек)</value></data>
<!-- Settings — Storage -->
<data name="Settings.Storage.DatabasePath"><value>Путь к SQLite</value></data>
+18
View File
@@ -16,4 +16,22 @@ public sealed class WorkerOptions
/// <summary>Whether the upcoming/pre-match poller should run at startup.</summary>
public bool UpcomingPollerEnabled { get; set; } = true;
/// <summary>
/// How long the live odds poller sleeps between cycles, in seconds.
/// Default: 30 s.
/// </summary>
public int LivePollIntervalSeconds { get; set; } = 30;
/// <summary>
/// Whether the results watch-list poller is enabled.
/// Default: false — disabled until Phase 8 is complete.
/// </summary>
public bool ResultsPollerEnabled { get; set; } = false;
/// <summary>
/// How long the results watch-list poller sleeps between cycles, in seconds.
/// Default: 300 s (5 minutes).
/// </summary>
public int ResultsPollIntervalSeconds { get; set; } = 300;
}