Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in
U
upgrade-data-crawler-be
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • ThinhNC
  • upgrade-data-crawler-be
  • Merge Requests
  • !12

Merged
Opened Sep 07, 2026 by ThinhNC@ThinhNC
  • Report abuse
Report abuse

feat(crawler): support real-time page persistence, partial export and prevent duplicate rerun

Overview

This pull request introduces real-time incremental page persistence, partial data export capability, safe cancellation handling, and duplicate rerun prevention to enhance reliability and data safety during crawl jobs.


Key Changes

1. Real-time Incremental Page Persistence

  • Firecrawl Polling (firecrawl.service.ts): Updated onProgress callback to stream currently scraped pages (currentPages) during active polling iterations for both full crawls and batch scrapes.
  • Worker Processor (crawl.worker.processor.ts):
    • Implemented persistIncrementalPages and persistSinglePage.
    • Crawled pages are now immediately normalized and upserted to the database (crawl_pages) during execution instead of waiting for the job to complete.
    • Added URL deduplication tracking (persistedUrls) to ensure idempotency.

2. Job Cancellation & State Preservation

  • Enhanced cancel flow in crawl.worker.processor.ts so when a job is canceled mid-execution:
    • All previously persisted pages are safely preserved.
    • successPages correctly reflects actual pages saved.
    • Job status remains CANCELED instead of being erroneously overridden to FAILED.

3. Partial Data Export Support

  • Export Service (crawl-export.service.ts):
    • Relaxed export eligibility to allow exports for jobs with status === "COMPLETED" as well as status IN ("CANCELED", "FAILED") as long as successPages > 0.
    • Appended warnings and metadata indicating partial dataset export.

4. Duplicate Rerun Prevention (Concurrency Guard)

  • Job Service & Repository (crawl-job.service.ts, crawl-job.repository.ts):
    • Introduced static in-memory concurrency mutex (rerunLocks) to prevent rapid consecutive clicks from creating multiple duplicate pending jobs.
    • Added findRecentActiveJob to deduplicate jobs requested with the same target URL and config within a 5-second window.

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b feat/realtime-page-persistence-and-partial-export origin/feat/realtime-page-persistence-and-partial-export

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout origin/develop
git merge --no-ff feat/realtime-page-persistence-and-partial-export

Step 4. Push the result of the merge to GitLab

git push origin develop

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 0
  • Commits 1
  • Changes 9
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
0
Labels
None
Assign labels
  • View project labels
Reference: ThinhNC/upgrade-data-crawler-be!12

Revert this merge request

This will create a new commit in order to revert the existing changes.

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.