mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +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
@@ -8,54 +8,93 @@ const { once } = require('node:events');
|
||||
const { setTimeout: delay } = require('node:timers/promises');
|
||||
const { createHash } = require('node:crypto');
|
||||
const volume = '/ql/data/db';
|
||||
const moduleFile = '/ql/static/build/shared/managedExit.cjs';
|
||||
const moduleFile = '/ql/static/build/cron/settlement/exitReceipt.cjs';
|
||||
const { receiptPath, readExit, retiringExits } = require(moduleFile);
|
||||
|
||||
(async () => {
|
||||
const usage = await fs.statfs(volume);
|
||||
assert.equal(usage.type,0xef53);
|
||||
assert.ok(usage.blocks * usage.bsize <= 32 * 1024 * 1024 && usage.files <= 8192);
|
||||
await fs.access(path.join(volume,'.qa-isolated-volume'));
|
||||
const root = await fs.mkdtemp(path.join(volume,'.qa-slot-'));
|
||||
assert.equal(usage.type, 0xef53);
|
||||
assert.ok(
|
||||
usage.blocks * usage.bsize <= 32 * 1024 * 1024 && usage.files <= 8192,
|
||||
);
|
||||
await fs.access(path.join(volume, '.qa-isolated-volume'));
|
||||
const root = await fs.mkdtemp(path.join(volume, '.qa-slot-'));
|
||||
const workers = [];
|
||||
try {
|
||||
process.env.QL_DATA_DIR = root;
|
||||
const id = 'occupied-slot', directory = path.join(path.dirname(receiptPath(id)),'.claim.' + id + '.qaTest');
|
||||
await fs.mkdir(directory,{recursive:true});
|
||||
const slot = path.join(directory,'receipt');
|
||||
const receipt = code => JSON.stringify({code, signal:null, time:1000, version:1,
|
||||
checksum:createHash('sha256').update(JSON.stringify([id,code,null,1000])).digest('hex')});
|
||||
await fs.writeFile(slot,receipt(17),{flag:'wx'});
|
||||
for (const role of ['A','B']) {
|
||||
const id = 'occupied-slot',
|
||||
directory = path.join(
|
||||
path.dirname(receiptPath(id)),
|
||||
'.claim.' + id + '.qaTest',
|
||||
);
|
||||
await fs.mkdir(directory, { recursive: true });
|
||||
const slot = path.join(directory, 'receipt');
|
||||
const receipt = (code) =>
|
||||
JSON.stringify({
|
||||
code,
|
||||
signal: null,
|
||||
time: 1000,
|
||||
version: 1,
|
||||
checksum: createHash('sha256')
|
||||
.update(JSON.stringify([id, code, null, 1000]))
|
||||
.digest('hex'),
|
||||
});
|
||||
await fs.writeFile(slot, receipt(17), { flag: 'wx' });
|
||||
for (const role of ['A', 'B']) {
|
||||
const barrier = path.join(root, role);
|
||||
const child = spawn(process.execPath,[path.join(__dirname,'receipt-claim-reuse-worker.cjs'),
|
||||
moduleFile, slot, id, '17', '1000', barrier],{stdio:'inherit'});
|
||||
workers.push({barrier,child,done:once(child,'exit')});
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[
|
||||
path.join(__dirname, 'receipt-claim-reuse-worker.cjs'),
|
||||
moduleFile,
|
||||
slot,
|
||||
id,
|
||||
'17',
|
||||
'1000',
|
||||
barrier,
|
||||
],
|
||||
{ stdio: 'inherit' },
|
||||
);
|
||||
workers.push({ barrier, child, done: once(child, 'exit') });
|
||||
}
|
||||
const deadline = performance.now() + 10000;
|
||||
const before = await Promise.all(workers.map(async ({barrier}) => {
|
||||
while (performance.now() < deadline) {
|
||||
try { return JSON.parse(await fs.readFile(barrier+'.ready','utf8')); }
|
||||
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
||||
await delay(20);
|
||||
}
|
||||
throw Error('Both collectors must validate the original slot');
|
||||
}));
|
||||
assert.equal(before[0].fileInode,before[1].fileInode);
|
||||
assert.equal(before[0].directoryInode,before[1].directoryInode);
|
||||
await fs.writeFile(slot+'.new',receipt(42),{flag:'wx'});
|
||||
await fs.rename(slot+'.new',slot);
|
||||
const before = await Promise.all(
|
||||
workers.map(async ({ barrier }) => {
|
||||
while (performance.now() < deadline) {
|
||||
try {
|
||||
return JSON.parse(await fs.readFile(barrier + '.ready', 'utf8'));
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') throw error;
|
||||
}
|
||||
await delay(20);
|
||||
}
|
||||
throw Error('Both collectors must validate the original slot');
|
||||
}),
|
||||
);
|
||||
assert.equal(before[0].fileInode, before[1].fileInode);
|
||||
assert.equal(before[0].directoryInode, before[1].directoryInode);
|
||||
await fs.writeFile(slot + '.new', receipt(42), { flag: 'wx' });
|
||||
await fs.rename(slot + '.new', slot);
|
||||
const inode = (await fs.stat(slot)).ino;
|
||||
assert.notEqual(inode,before[0].fileInode);
|
||||
for (const {barrier} of workers) await fs.writeFile(barrier+'.go','');
|
||||
for (const {done} of workers) assert.deepEqual(await done,[0,null]);
|
||||
assert.notEqual(inode, before[0].fileInode);
|
||||
for (const { barrier } of workers) await fs.writeFile(barrier + '.go', '');
|
||||
for (const { done } of workers) assert.deepEqual(await done, [0, null]);
|
||||
const captures = await retiringExits();
|
||||
assert.equal(captures.length,1);
|
||||
assert.equal((await fs.stat(captures[0].file)).ino,inode);
|
||||
assert.equal((await readExit(id,captures[0].file)).code,42);
|
||||
console.log(JSON.stringify({before,replacementInode:inode,retained:captures[0].file}));
|
||||
assert.equal(captures.length, 1);
|
||||
assert.equal((await fs.stat(captures[0].file)).ino, inode);
|
||||
assert.equal((await readExit(id, captures[0].file)).code, 42);
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
before,
|
||||
replacementInode: inode,
|
||||
retained: captures[0].file,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
for (const {child} of workers) if (child.exitCode === null) child.kill();
|
||||
await fs.rm(root,{recursive:true,force:true});
|
||||
for (const { child } of workers) if (child.exitCode === null) child.kill();
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
})().catch(error => { console.error(error); process.exitCode=1; });
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in new issue
Block a user