mirror of
https://github.com/alexhopeoconnor/bom-local-service.git
synced 2026-10-04 03:28:11 +10:00
- Remove OpenAPI/Swagger support and all related code - Standardize configuration: remove hardcoded defaults, all defaults from appsettings.json - Configuration values throw exceptions if missing (except Debug:Enabled defaults to false) - Refactor CacheManagementService: extract ProcessLocationsAsync helper, remove duplicate code - Combine UpdateStaggerSeconds and LocationStaggerSeconds into single LocationStaggerSeconds config - Move config reads to constructors for better performance - Update README and docker-compose.yml to reflect configuration changes
64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using BomLocalService.Services.Interfaces;
|
|
using BomLocalService.Services.Scraping;
|
|
using Microsoft.Playwright;
|
|
|
|
namespace BomLocalService.Services.Scraping.Steps.Navigation;
|
|
|
|
public class NavigateHomepageStep : BaseScrapingStep
|
|
{
|
|
private readonly string _baseUrl;
|
|
|
|
public override string Name => "NavigateHomepage";
|
|
public override string[] Prerequisites => Array.Empty<string>();
|
|
|
|
public NavigateHomepageStep(
|
|
ILogger<NavigateHomepageStep> logger,
|
|
ISelectorService selectorService,
|
|
IDebugService debugService,
|
|
IConfiguration configuration)
|
|
: base(logger, selectorService, debugService, configuration)
|
|
{
|
|
_baseUrl = configuration.GetValue<string>("Scraping:BaseUrl")
|
|
?? throw new InvalidOperationException("Scraping:BaseUrl configuration is required. Set it in appsettings.json or via SCRAPING__BASEURL environment variable.");
|
|
}
|
|
|
|
public override bool CanExecute(ScrapingContext context)
|
|
{
|
|
return context.CurrentState == PageState.Initial;
|
|
}
|
|
|
|
public override async Task<ScrapingStepResult> ExecuteAsync(ScrapingContext context, CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
Logger.LogInformation("Step {Step}: Navigating to BOM homepage", Name);
|
|
|
|
await context.Page.GotoAsync(_baseUrl, new PageGotoOptions
|
|
{
|
|
WaitUntil = WaitUntilState.DOMContentLoaded,
|
|
Timeout = 30000
|
|
});
|
|
|
|
// Wait for search button to be ready
|
|
var searchButtonReady = SelectorService.GetLocator(context.Page, Selectors.SearchButton);
|
|
await searchButtonReady.WaitForAsync(new LocatorWaitForOptions
|
|
{
|
|
Timeout = Selectors.SearchButton.TimeoutMs,
|
|
State = WaitForSelectorState.Visible
|
|
});
|
|
|
|
await SaveDebugAsync(context, 1, "homepage_loaded", cancellationToken);
|
|
|
|
context.CurrentState = PageState.HomepageLoaded;
|
|
return ScrapingStepResult.Successful();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex, "Step {Step} failed", Name);
|
|
await SaveErrorDebugAsync(context, $"Failed to navigate to homepage: {ex.Message}", cancellationToken);
|
|
return ScrapingStepResult.Failed($"Failed to navigate to homepage: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
|