SCRAPE-12: Implement in-process mutex (isScraperRunning flag) #17

Merged
stephen merged 1 commits from scraper/mutex into dev 2026-02-06 16:27:29 -07:00
Owner

Summary

  • Adds an in-process mutex lock module (jobs/scraperJob.js) to prevent concurrent scraper executions
  • Implements four exported functions: acquireLock(jobId), releaseLock(), isScraperRunning(), and getCurrentJobId()
  • acquireLock returns a boolean indicating whether the lock was successfully acquired, preventing re-entry when a scrape is already in progress
  • releaseLock clears the lock state and job ID, allowing subsequent runs

Test Coverage

  • 19 unit tests in tests/scraper/scraperJob.test.js
  • Covers lock acquisition, release, re-entry prevention, state queries, idempotent release, and module export verification

Test Plan

  • All 19 scraperJob tests pass
  • No regressions in existing scraper test suite
  • Rebased cleanly on latest dev
## Summary - Adds an in-process mutex lock module (jobs/scraperJob.js) to prevent concurrent scraper executions - Implements four exported functions: acquireLock(jobId), releaseLock(), isScraperRunning(), and getCurrentJobId() - acquireLock returns a boolean indicating whether the lock was successfully acquired, preventing re-entry when a scrape is already in progress - releaseLock clears the lock state and job ID, allowing subsequent runs ## Test Coverage - 19 unit tests in __tests__/scraper/scraperJob.test.js - Covers lock acquisition, release, re-entry prevention, state queries, idempotent release, and module export verification ## Test Plan - All 19 scraperJob tests pass - No regressions in existing scraper test suite - Rebased cleanly on latest dev
stephen added 1 commit 2026-02-06 16:26:19 -07:00
feat: add in-process mutex to prevent concurrent scraper runs
All checks were successful
CI/CD Pipeline - Apartment API / Scan Dependencies (pull_request) Successful in 13s
CI/CD Pipeline - Apartment API / Lint & Test (pull_request) Successful in 38s
CI/CD Pipeline - Apartment API / Send Webhook Notification (pull_request) Successful in 2s
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
df86a1423c
Implement a lightweight in-process mutex lock for the scraper job
scheduler. This prevents multiple scraper instances from running
simultaneously, which could cause duplicate data and race conditions.

Exported functions:
- acquireLock(jobId): Attempts to acquire the mutex, returns boolean
- releaseLock(): Releases the mutex lock
- isScraperRunning(): Returns current lock state
- getCurrentJobId(): Returns the active job ID or null

Includes 19 unit tests covering lock acquisition, release, re-entry
prevention, and edge cases.
stephen merged commit dd0269eb30 into dev 2026-02-06 16:27:29 -07:00
stephen deleted branch scraper/mutex 2026-02-06 16:27:30 -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#17
No description provided.