mirror of
https://github.com/whyour/qinglong.git
synced 2026-11-30 16:27:21 +08:00
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.
52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
// Stable supervisor entry point. Receipt storage is a separate, service-free module.
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const {
|
|
parseExit,
|
|
writeExit,
|
|
receiptPath,
|
|
storageFull,
|
|
} = require('../cron/settlement/exitReceipt.cjs');
|
|
const idPattern = /^[a-z0-9-]{1,120}$/;
|
|
|
|
if (require.main === module) {
|
|
const id = process.env.QL_TRIGGER_ID;
|
|
const exit = parseExit(id, JSON.parse(process.argv[2]));
|
|
if (!idPattern.test(id || '') || !exit)
|
|
throw new Error('Invalid supervisor exit receipt');
|
|
const { code, signal, time } = exit;
|
|
// An older supervisor may only have delivered this tuple in its message.
|
|
// Journal it before waiting for the SQLite writer or loading the panel.
|
|
let journaled = false;
|
|
if (exit.version === 1) {
|
|
try {
|
|
writeExit(id, code, signal, time);
|
|
journaled = Boolean(receiptPath(id));
|
|
} catch (error) {
|
|
console.error('[scheduler] Could not journal supervisor message:', error);
|
|
}
|
|
}
|
|
// Development workers run TypeScript directly. Released panels load the
|
|
// compiled module without starting another runtime on ordinary exits.
|
|
if (!fs.existsSync(path.join(__dirname, '../cron/history.js'))) {
|
|
process.env.TS_NODE_PROJECT = path.join(__dirname, '../tsconfig.json');
|
|
require('ts-node/register/transpile-only');
|
|
}
|
|
const { triggerHistory } = require('../cron/history');
|
|
triggerHistory()
|
|
.complete(
|
|
id,
|
|
signal || code !== 0 ? 'failed' : 'finished',
|
|
signal,
|
|
code,
|
|
time,
|
|
exit.version === 1 ? exit : 'legacy',
|
|
)
|
|
.catch((error) => {
|
|
if (journaled && storageFull(error)) return;
|
|
console.error('[scheduler] Failed to settle orphaned command:', error);
|
|
process.exitCode = storageFull(error) ? 75 : 1;
|
|
})
|
|
.finally(() => require('../data').sequelize.close());
|
|
}
|