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

Co-authored-by: Stephen Minakian <stephenminakian@gmail.com>
Co-committed-by: Stephen Minakian <stephenminakian@gmail.com>
This commit is contained in:
2026-02-06 16:27:29 -07:00
committed by stephen
parent d818296eeb
commit dd0269eb30
2 changed files with 199 additions and 0 deletions

48
jobs/scraperJob.js Normal file
View File

@ -0,0 +1,48 @@
// In-process mutex state
let isRunning = false;
let currentJobId = null;
/**
* Check if scraper is currently running
* @returns {boolean}
*/
function isScraperRunning() {
return isRunning;
}
/**
* Get current job ID if running
* @returns {string|null}
*/
function getCurrentJobId() {
return currentJobId;
}
/**
* Acquire the scraper lock
* @param {string} jobId - Job ID to set
* @returns {boolean} True if lock acquired
*/
function acquireLock(jobId) {
if (isRunning) {
return false;
}
isRunning = true;
currentJobId = jobId;
return true;
}
/**
* Release the scraper lock
*/
function releaseLock() {
isRunning = false;
currentJobId = null;
}
module.exports = {
isScraperRunning,
getCurrentJobId,
acquireLock,
releaseLock
};