mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 18:40:37 +08:00
feat(cron): expose run receipts and modularize execution
Return committed trigger IDs and add CLI wait and trigger-specific logs while preserving API, CLI, transaction, deduplication and unknown-result semantics. Move scheduling, lifecycle, settlement, queries and legacy adapters into back/cron; remove obsolete internal import paths and circular dependencies. Apply project formatting across the repository, cover CJS/MJS in formatting hooks, add prettier:check and require formatting checks in AGENTS.md. Validation: backend build; 1398 backend/frontend tests passed (17 platform skips); 327 CLI tests passed (6 platform skips); 670 files pass format checks.
This commit is contained in:
1 parent
77ece406ac
commit
c5458596c8
346 files changed
+32133
-11556
No files matched your search
@@ -1,6 +1,7 @@
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const [moduleFile, file, id, outcome, time, barrier, recovery, stage] = process.argv.slice(2);
|
||||
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);
|
||||
@@ -10,38 +11,69 @@ async function gate(suffix, data, release) {
|
||||
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));
|
||||
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,
|
||||
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 };
|
||||
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}));
|
||||
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');
|
||||
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 => {
|
||||
fs.promises.unlink = async (file) => {
|
||||
if (stage === 'holdUnlink' && captured === file)
|
||||
await gate('.checked', {target:file, inode:(await fs.promises.stat(file)).ino}, '.release');
|
||||
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();
|
||||
});
|
||||
? 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