mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 18:07:21 +08:00
feat: harden cron execution recovery and expose scheduling diagnostics
Reconcile scheduled and system cron triggers, isolate concurrent executions and retain verifiable exit statistics across restarts. Add paged task history, log and script browsing, dashboard timing details and regression coverage.
This commit is contained in:
1 parent
3b6a873520
commit
8a9e70e90b
166 files changed
+18942
-1800
No files matched your search
@@ -0,0 +1,47 @@
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const [moduleFile, file, id, outcome, time, barrier, recovery, stage] = process.argv.slice(2);
|
||||
const { retireLegacyFile } = require(moduleFile);
|
||||
// Both collectors have read the source and hold its directory lock at this point.
|
||||
const rename = fs.promises.rename.bind(fs.promises);
|
||||
let captured;
|
||||
async function gate(suffix, data, release) {
|
||||
fs.writeFileSync(barrier + '.tmp', JSON.stringify(data));
|
||||
fs.renameSync(barrier + '.tmp', barrier + suffix);
|
||||
const limit = performance.now() + 90000;
|
||||
while (!fs.existsSync(barrier + release)) {
|
||||
if (performance.now() > limit) throw Error('Timed out waiting for ' + release);
|
||||
await new Promise(resolve => setTimeout(resolve, 25));
|
||||
}
|
||||
}
|
||||
fs.promises.rename = async (source, target) => {
|
||||
if (await fs.promises.realpath(source) !== file) return rename(source, target);
|
||||
const ready = { pid: process.pid, path:file, target,
|
||||
directoryInode: (await fs.promises.stat(path.dirname(source))).ino,
|
||||
fileInode: (await fs.promises.stat(source)).ino };
|
||||
await gate('.ready', ready, '.go');
|
||||
try {
|
||||
await rename(source, target);
|
||||
} catch (error) {
|
||||
if (stage === 'recordMoveError')
|
||||
fs.writeFileSync(barrier + '.error', JSON.stringify({code:error.code, errno:error.errno, syscall:error.syscall}));
|
||||
throw error;
|
||||
}
|
||||
captured = target;
|
||||
if (stage === 'holdMoved') await gate('.moved', {target, inode:(await fs.promises.stat(target)).ino}, '.release');
|
||||
};
|
||||
const unlink = fs.promises.unlink.bind(fs.promises);
|
||||
fs.promises.unlink = async file => {
|
||||
if (stage === 'holdUnlink' && captured === file)
|
||||
await gate('.checked', {target:file, inode:(await fs.promises.stat(file)).ino}, '.release');
|
||||
return unlink(file);
|
||||
};
|
||||
const settlement = recovery
|
||||
? require(recovery).triggerHistory().complete(id,'unknown',null,null)
|
||||
: retireLegacyFile(id, file, {outcome, time:Number(time)});
|
||||
settlement.catch(error => {
|
||||
// Another collector may have already removed the same settled inode.
|
||||
if (error.code !== 'ENOENT') { console.error(error); process.exitCode = 1; }
|
||||
}).finally(() => {
|
||||
if (recovery) return require(path.join(path.dirname(recovery),'../data')).sequelize.close();
|
||||
});
|
||||
Reference in new issue
Block a user