SCRAPE-17: Implement GET /admin/scraper/status endpoint #22

Merged
stephen merged 1 commits from scraper/api-status into dev 2026-02-06 22:20:06 -07:00
Owner

Summary

  • Add GET /api/admin/scraper/status endpoint to provide real-time scraper system status
  • Protected by requireAuth + requireAdmin middleware
  • Returns comprehensive status object with five fields:
    • currentStatus: idle or running based on mutex state
    • runningJobId: active job ID when running, null when idle
    • lastRun: most recent entry from scraper_runs collection (status, startedAt, completedAt, duration, unitsProcessed, pricesRecorded, errors), or null if no runs exist
    • nextScheduledRun: ISO timestamp of next scheduled execution, or null if scheduler is disabled
    • schedule: cron expression string for the configured schedule

Technical Details

  • Queries scraper_runs collection sorted by startedAt descending, limited to 1 result
  • Returns 503 with error Service temporarily unavailable on database errors
  • Follows existing admin route patterns in routes/admin.js

Test Coverage

  • 13 tests covering:
    • Authentication (401 without auth)
    • Authorization (403 for non-admin)
    • All response fields with various mutex/scheduler states
    • Last run with and without errors
    • Multiple runs returning most recent
    • Database error handling (503)
## Summary - Add GET /api/admin/scraper/status endpoint to provide real-time scraper system status - Protected by requireAuth + requireAdmin middleware - Returns comprehensive status object with five fields: - currentStatus: idle or running based on mutex state - runningJobId: active job ID when running, null when idle - lastRun: most recent entry from scraper_runs collection (status, startedAt, completedAt, duration, unitsProcessed, pricesRecorded, errors), or null if no runs exist - nextScheduledRun: ISO timestamp of next scheduled execution, or null if scheduler is disabled - schedule: cron expression string for the configured schedule ## Technical Details - Queries scraper_runs collection sorted by startedAt descending, limited to 1 result - Returns 503 with error Service temporarily unavailable on database errors - Follows existing admin route patterns in routes/admin.js ## Test Coverage - 13 tests covering: - Authentication (401 without auth) - Authorization (403 for non-admin) - All response fields with various mutex/scheduler states - Last run with and without errors - Multiple runs returning most recent - Database error handling (503)
stephen added 1 commit 2026-02-06 21:31:18 -07:00
feat: add GET /api/admin/scraper/status endpoint
Some checks failed
CI/CD Pipeline - Apartment API / Scan Dependencies (pull_request) Successful in 12s
CI/CD Pipeline - Apartment API / Lint & Test (pull_request) Successful in 40s
CI/CD Pipeline - Apartment API / Send Webhook Notification (pull_request) Failing after 1s
CI/CD Pipeline - Apartment API / Build & Push Image (pull_request) Has been skipped
CI/CD Pipeline - Apartment API / Deploy to Production (pull_request) Has been skipped
2b36ef4e23
Implement a status endpoint that returns the current state of the
scraper system. The response includes mutex state (idle/running with
job ID), last run history from scraper_runs collection (status,
timing, unit/error counts), next scheduled run timestamp, and
cron schedule expression.

Protected by requireAuth + requireAdmin middleware. Returns 503
on database errors for graceful degradation. Includes 13 tests
covering auth, response structure, edge cases, and error handling.
stephen force-pushed scraper/api-status from 2b36ef4e23 to 1c89181d87 2026-02-06 22:18:22 -07:00 Compare
stephen merged commit 9d0b9debbb into dev 2026-02-06 22:20:06 -07:00
stephen deleted branch scraper/api-status 2026-02-06 22:20:07 -07:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: stephen/apartment-dashboard-api#22
No description provided.