@sidequest/engine
Version:
@sidequest/engine is the core engine of SideQuest, a distributed background job processing system for Node.js and TypeScript.
29 lines (25 loc) • 1.07 kB
JavaScript
;
var core = require('@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) {
core.logger("Engine").info(`Stale jobs found, making them available to process`);
core.logger("Engine").debug(`Stale jobs: ${JSON.stringify(staleJobs)}`);
for (const jobData of staleJobs) {
jobData.state = "waiting";
await backend.updateJob(jobData);
}
}
else {
core.logger("Engine").debug(`No stale jobs found`);
}
}
exports.releaseStaleJobs = releaseStaleJobs;
//# sourceMappingURL=release-stale-jobs.cjs.map