Batched URL Validation System
Batched URL Validation System
This document explains the batched URL validation system designed to handle ~80k+ government URLs across 60 countries without exceeding GitHub Actionsβ 2-hour timeout limit.
Problem
The original implementation attempted to validate all URLs in a single GitHub Actions run, which:
- Exceeded the 2-hour timeout limit
- Was not resumable if it failed partway through
- Couldnβt track progress across multiple runs
Solution
The batched validation system breaks the work into small chunks that can be:
- Executed within the 2-hour timeout
- Tracked across multiple workflow runs
- Monitored via GitHub Issues
- Automatically resumed every 2 hours via cron
Architecture
Components
- Batch Coordinator (
src/services/batch_coordinator.py)- Manages validation cycles and tracks progress
- Assigns countries to batches
- Persists state in SQLite database
- GitHub Issue Manager (
src/services/github_issue_manager.py)- Creates and updates GitHub issues to track cycle progress
- Closes issues when cycles complete
- Uses GitHub CLI (
gh)
- Batch CLI (
src/cli/validate_urls_batch.py)- Command-line interface for batch validation
- Processes countries in configurable batch sizes
- Integrates with coordinator and issue manager
- Workflow Files
.github/workflows/validate-urls-batch.yml- Runs every 2 hours.github/workflows/reopen-validation-cycle.yml- Starts new cycles quarterly
Database Schema
The validation_batch_state table tracks cycle progress:
CREATE TABLE validation_batch_state (
cycle_id TEXT NOT NULL, -- Format: YYYYMMDD-HHMMSS
country_code TEXT NOT NULL, -- e.g., "TEXAS", "CALIFORNIA"
status TEXT NOT NULL, -- pending, processing, completed, failed
started_at TEXT, -- ISO timestamp
completed_at TEXT, -- ISO timestamp
github_issue_number INTEGER, -- GitHub issue tracking this cycle
error_message TEXT, -- Error details if failed
PRIMARY KEY (cycle_id, country_code)
);
Usage
Manual Batch Validation
Process the next 5 countries and create a GitHub issue:
python3 -m src.cli.validate_urls_batch \
--batch-mode \
--batch-size 5 \
--rate-limit 2.0 \
--create-issue
Process specific batch size with existing issue:
python3 -m src.cli.validate_urls_batch \
--batch-mode \
--batch-size 10 \
--github-issue 123
Single Country Validation (Legacy)
Validate a specific country:
python3 -m src.cli.validate_urls_batch \
--country TEXAS \
--rate-limit 2.0
Automatic Batch Processing
The system automatically:
- Every 2 hours: Processes next batch via cron workflow
- Quarterly: Starts new validation cycles (Jan 1, Apr 1, Jul 1, Oct 1)
Workflow
1. Cycle Initiation
When a new cycle starts:
- All countries are initialized with
status = 'pending' - A GitHub issue is created to track progress
- Cycle ID is generated (format:
YYYYMMDD-HHMMSS)
2. Batch Processing
Every 2 hours:
- Workflow runs via cron trigger
- Downloads previous metadata DB from artifacts
- Gets next N countries (default: 5) with
status = 'pending' - Marks them as
status = 'processing' - Validates URLs for each country
- Updates status to
completedorfailed - Updates GitHub issue with progress
- Uploads metadata DB as artifact
3. Cycle Completion
When all countries are complete:
- GitHub issue is automatically closed
- Final statistics are reported
- System waits for next quarterly cycle or manual restart
4. Progress Tracking
GitHub issue shows:
Status: π‘ In Progress
ββββββββββββββββββββ 60.0%
β
Completed: 36/60
π Processing: 2
β³ Pending: 20
β Failed: 2
Configuration
Batch Size
Adjust based on:
- Average URLs per country
- Rate limiting settings
- Desired completion time
Default: 5 countries per batch (~1.5 hours with 2 req/sec)
Rate Limiting
Default: 2.0 requests/second per country
Configurable via:
- CLI:
--rate-limit 5.0 - Workflow:
rate_limitinput parameter
Timeout
Default: 110 minutes (leaves 10-minute buffer)
Configured in workflow file: timeout-minutes: 110
Monitoring
Check Cycle Progress
python3 -c "
from src.services.batch_coordinator import BatchCoordinator
from pathlib import Path
coordinator = BatchCoordinator(Path('data/metadata.db'))
# Get latest cycle
progress = coordinator.get_cycle_progress('CYCLE_ID')
print(progress)
"
View GitHub Issue
Issues are labeled with:
url-validationautomated
Find open issues: https://github.com/mgifford/dot-gov-scans/issues?q=is%3Aissue+is%3Aopen+label%3Aurl-validation
Resumability
The system is fully resumable:
- State persists in database artifact
- Workflow restarts automatically every 2 hours
- Progress tracked in GitHub issue
- Failed countries can be retried in next cycle
Cost Optimization
- Artifact storage: Only metadata DB (~1 MB) uploaded
- Workflow minutes: ~2 hours per batch, spread over days
- Rate limiting: Respects server limits, prevents blocks
Example Timeline
For 60 countries with batch size 5:
| Time | Batch | Countries | Status |
|---|---|---|---|
| T+0h | 1 | 5 | β Completed |
| T+2h | 2 | 5 | β Completed |
| T+4h | 3 | 5 | β Completed |
| β¦ | β¦ | β¦ | β¦ |
| T+22h | 12 | 5 | β Completed |
| T+24h | - | 60 | π’ Cycle Complete |
Total time: ~24 hours to validate all 60 countries
Troubleshooting
Issue not created
- Ensure
ghCLI is available in workflow - Check
GH_TOKENpermissions includeissues: write - Check repository settings allow workflow to create issues
Batch doesnβt resume
- Verify metadata DB artifact exists
- Check artifact retention (90 days)
- Ensure cycle isnβt marked complete
Countries skipped
- Check TOON files exist in
data/toon-seeds/ - Verify country code matches filename
- Check error messages in batch state table
Future Improvements
- Adaptive batch sizing: Adjust based on URL count per country
- Parallel processing: Process multiple countries concurrently
- Priority queuing: Prioritize countries by update frequency
- Webhook notifications: Alert on cycle completion
- Web dashboard: Real-time progress visualization