Skip to content

feat: Implement background crawling jobs (6/6) - #62

Merged
KevinJBoyer merged 6 commits into
kb/crawl-job-3-3from
kb/crawl-job-3-4
Oct 29, 2025
Merged

feat: Implement background crawling jobs (6/6)#62
KevinJBoyer merged 6 commits into
kb/crawl-job-3-3from
kb/crawl-job-3-4

Conversation

@KevinJBoyer

@KevinJBoyer KevinJBoyer commented Oct 28, 2025

Copy link
Copy Markdown

Ticket

https://navalabs.atlassian.net/browse/DST-1251
https://navalabs.atlassian.net/browse/DST-1252

Changes

  • Add OpenAI Web Search Component
  • Add crawl job script + test coverage
  • Add prompt version for GCTA crawling script

Context for reviewers

  • For local testing, gpt-5 and high reasoning effort is quite slow, so you may want to manually modify the code to gpt-5-mini and medium. (I don't recommend going lower because then the model is unlikely to respond with valid JSON.)

Testing

echo "OPENAI_API_KEY=..." >> override.env
make copy-prompts

make manage-crawl-job ACTION="upsert" PROMPT_NAME="crawl_gcta" DOMAIN="gctatraining.org" INTERVAL=24

make process-crawl-jobs

See entries in database:
image

Re-run make process-crawl-jobs and confirm it does nothing because the crawl interval is every 24 hours:
image

Preview environment for frontend

♻️ Environment destroyed ♻️

Preview environment for app

♻️ Environment destroyed ♻️

Comment thread app/src/ingestion/process_crawl_jobs.py Outdated

@yoomlam yoomlam left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering what behavior is desired if anything fails

tasks = [run_pipeline(pipeline, job) for job in jobs]
results = await asyncio.gather(*tasks)

# Combine jobs with their results and convert to SupportEntry objects

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If one of the jobs fail, do we want SupportEntry records from successful jobs to be created?

Comment thread app/src/ingestion/process_crawl_jobs.py Outdated
Comment thread app/src/ingestion/process_crawl_jobs.py Outdated
Comment on lines +256 to +258
for job, support_entries in results:
logger.info("Saving results for domain: %s", job.domain)
save_job_results(db_session, job, support_entries.values())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if a job fails? Is the effect desirable?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated: if a job fails, an error is logged but other jobs continue and will save their results to the db.

Comment on lines +266 to +267
with config.db_session() as db_session, db_session.begin():
process_all_jobs(db_session)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any exception is raised, nothing should be commited to the DB.

@KevinJBoyer KevinJBoyer Oct 28, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I double-checked that's the behavior of db_session.begin() in a context manager (if process_all_jobs were to raise an uncaught exception, the transaction would be rolled back rather than committed)

@KevinJBoyer

KevinJBoyer commented Oct 28, 2025

Copy link
Copy Markdown
Author

@yoomlam thanks for the feedback! I update the job filtering logic to happen in a query, and updated the parallel processing to let individual jobs fail while still saving the results from any jobs that succeed. (I also switched back to ChatPromptBuilder!)

@KevinJBoyer
KevinJBoyer requested a review from yoomlam October 28, 2025 19:33
continue

# Deduplicate by name
support_entries = {entry["name"]: SupportEntry(**entry) for entry in result}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting that this deduplicates within a job, not across jobs.

@KevinJBoyer
KevinJBoyer merged commit 5bcf63c into kb/crawl-job-3-3 Oct 29, 2025
11 of 12 checks passed
@KevinJBoyer
KevinJBoyer deleted the kb/crawl-job-3-4 branch October 29, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants