@sidequest/engine
Version:
@sidequest/engine is the core engine of SideQuest, a distributed background job processing system for Node.js and TypeScript.
27 lines (24 loc) • 1.02 kB
JavaScript
import { logger } from '@sidequest/core';
/**
* Finds and releases stale jobs, making them available for processing again.
* @param backend The backend instance to operate on.
* @param maxStaleMs Maximum age of a job to be considered stale.
* @param maxClaimedMs Maximum age of a claimed job to be considered stale.
* @returns A promise that resolves when the operation is complete.
*/
async function releaseStaleJobs(backend, maxStaleMs, maxClaimedMs) {
const staleJobs = await backend.staleJobs(maxStaleMs, maxClaimedMs);
if (staleJobs.length > 0) {
logger("Engine").info(`Stale jobs found, making them available to process`);
logger("Engine").debug(`Stale jobs: ${JSON.stringify(staleJobs)}`);
for (const jobData of staleJobs) {
jobData.state = "waiting";
await backend.updateJob(jobData);
}
}
else {
logger("Engine").debug(`No stale jobs found`);
}
}
export { releaseStaleJobs };
//# sourceMappingURL=release-stale-jobs.js.map