feat: add page-fetcher-api — centralised Playwright page fetcher

Introduces page-fetcher-api, a new internal ASP.NET Core service that
centralises all web-page fetching through a single Playwright (headless
Chromium) browser instance. All fetches are persisted to the pageFetcher
SQL schema for auditing.

New projects:
- Apis/page-fetcher-api-models: FetchPageRequest, FetchPageResponse, IPageFetcherApiClient
- Apis/page-fetcher-data: PageFetchDbContext, PageFetchEntity, InitialSchema migration (schema: pageFetcher)
- Apis/page-fetcher-api: PlaywrightBrowserService (singleton), PageFetcherService, PageController

Changes to existing services:
- cv-matcher-api: JobTextExtractor now calls IPageFetcherApiClient instead of HttpClient
- cv-search-job: HtmlJobSearcher uses IPageFetcherApiClient (removes inline Playwright);
  CvSearchJobTask fetches individual job pages and applies keyword pre-filter before
  LLM call; passes pre-fetched JobDescription to cv-matcher-api to skip re-fetch
- common: add PageFetcherApiSettings
- docker-compose.yml, build.yml: add new service + env vars for callers

Closes #43

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 17:43:56 +03:00
parent 1222a86eb7
commit 898dd09d50
31 changed files with 1121 additions and 110 deletions
+44 -10
View File
@@ -11,6 +11,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using PageFetcher.Models;
namespace CvSearchJob.Tasks;
@@ -24,6 +25,7 @@ public sealed class CvSearchJobTask : IJobTask
private readonly JobSearchSettings _settings;
private readonly HtmlJobSearcher _searcher;
private readonly ICvMatcherInternalApi _matcherApi;
private readonly IPageFetcherApiClient _pageFetcher;
private readonly CvSearchEmailSender _emailSender;
private readonly ILogger<CvSearchJobTask> _logger;
@@ -34,6 +36,7 @@ public sealed class CvSearchJobTask : IJobTask
IOptions<JobSearchSettings> settings,
HtmlJobSearcher searcher,
ICvMatcherInternalApi matcherApi,
IPageFetcherApiClient pageFetcher,
CvSearchEmailSender emailSender,
ILogger<CvSearchJobTask> logger)
{
@@ -41,6 +44,7 @@ public sealed class CvSearchJobTask : IJobTask
_settings = settings.Value;
_searcher = searcher;
_matcherApi = matcherApi;
_pageFetcher = pageFetcher;
_emailSender = emailSender;
_logger = logger;
}
@@ -126,7 +130,8 @@ public sealed class CvSearchJobTask : IJobTask
/// <summary>
/// Runs the full search pipeline for a session: scrapes all providers, deduplicates URLs,
/// scores each candidate via the matcher API, and persists results that meet the minimum score threshold.
/// fetches each individual job page via page-fetcher-api, applies a keyword pre-filter,
/// scores passing candidates via the matcher API, and persists results that meet the minimum score threshold.
/// </summary>
private async Task<List<JobSearchResultEntity>> RunSearchAsync(
JobSearchSessionEntity session,
@@ -138,30 +143,59 @@ public sealed class CvSearchJobTask : IJobTask
if (cvKeywords.Count == 0)
_logger.LogWarning("Session {SessionId}: keyword list is empty — scraper will rely on provider InitialKeywords only", session.Id);
var jobUrls = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var jobCandidates = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); // url → title
foreach (var provider in providers)
{
var urls = await _searcher.SearchJobUrlsAsync(provider, cvKeywords, session.Location, ct);
_logger.LogInformation("Session {SessionId}: provider {Provider} returned {Count} URLs", session.Id, provider.Name, urls.Count);
foreach (var url in urls) jobUrls.Add(url);
var candidates = await _searcher.SearchJobUrlsAsync(provider, cvKeywords, session.Location, ct);
_logger.LogInformation("Session {SessionId}: provider {Provider} returned {Count} candidates", session.Id, provider.Name, candidates.Count);
foreach (var c in candidates)
jobCandidates.TryAdd(c.Url, c.Title);
}
var candidates = jobUrls.Take(_settings.MaxJobsToMatch).ToList();
var deduped = jobCandidates.Take(_settings.MaxJobsToMatch).ToList();
_logger.LogInformation(
"Session {SessionId}: {Total} unique URLs across all providers, scoring {Scoring} (cap={Cap})",
session.Id, jobUrls.Count, candidates.Count, _settings.MaxJobsToMatch);
"Session {SessionId}: {Total} unique URLs across all providers, processing up to {Cap}",
session.Id, jobCandidates.Count, deduped.Count);
var results = new List<JobSearchResultEntity>();
foreach (var url in candidates)
foreach (var (url, title) in deduped)
{
try
{
// Fetch individual job page text via page-fetcher-api
var fetchResponse = await _pageFetcher.FetchAsync(new FetchPageRequest
{
Url = url,
WaitFor = "domcontentloaded",
CallerService = "cv-search-job"
}, ct);
if (!fetchResponse.Success || string.IsNullOrWhiteSpace(fetchResponse.Text))
{
_logger.LogWarning("Session {SessionId}: fetch failed for {Url} — {Error}", session.Id, url, fetchResponse.Error);
continue;
}
var jobText = fetchResponse.Text;
// Keyword pre-filter: skip LLM call if no CV keyword appears in the job page text
if (cvKeywords.Count > 0 &&
!cvKeywords.Any(k => jobText.Contains(k, StringComparison.OrdinalIgnoreCase)))
{
_logger.LogInformation(
"Session {SessionId}: pre-filter skip | {Url} | no CV keyword found in job text",
session.Id, url);
continue;
}
var matchRequest = new MatchJobRequest
{
CvDocumentId = session.CvDocumentId,
JobUrl = url,
// Pre-fetched text passed directly so cv-matcher-api skips re-fetching the page
JobDescription = jobText,
// User already gave GDPR consent when they clicked the one-time job search link
GdprConsent = true
};
@@ -182,7 +216,7 @@ public sealed class CvSearchJobTask : IJobTask
SessionId = session.Id,
ProviderName = GuessProvider(url, providers),
JobUrl = url,
JobTitle = matchResult.Summary.Split('.').FirstOrDefault()?.Trim() ?? "Job",
JobTitle = matchResult.Summary.Split('.').FirstOrDefault()?.Trim() ?? title,
JobText = string.Empty,
Score = matchResult.Score,
ResultJson = JsonSerializer.Serialize(matchResult, new JsonSerializerOptions(JsonSerializerDefaults.Web)),