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
@@ -1,7 +1,9 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { createCronJob } = require('../../back/shared/cronScheduler');
|
||||
const { isValidCronSchedule } = require('../../back/shared/cronSchedule');
|
||||
const { createCronJob } = require('../../back/cron/scheduling/cronScheduler');
|
||||
const {
|
||||
isValidCronSchedule,
|
||||
} = require('../../back/cron/scheduling/cronSchedule');
|
||||
|
||||
// node-cron caches timezone formatters; model each deployment in a fresh process.
|
||||
if (!process.env.QL_MACRO_TEST_TZ) {
|
||||
@@ -9,30 +11,65 @@ if (!process.env.QL_MACRO_TEST_TZ) {
|
||||
test(`macro execution in ${tz}`, () => {
|
||||
const env = { ...process.env, TZ: tz, QL_MACRO_TEST_TZ: tz };
|
||||
delete env.NODE_TEST_CONTEXT;
|
||||
const result = require('node:child_process').spawnSync(process.execPath,
|
||||
const result = require('node:child_process').spawnSync(
|
||||
process.execPath,
|
||||
['-r', 'ts-node/register/transpile-only', '--test', __filename],
|
||||
{ env, encoding: 'utf8' });
|
||||
{ env, encoding: 'utf8' },
|
||||
);
|
||||
assert.equal(result.status, 0, result.stdout + result.stderr);
|
||||
assert.match(result.stdout, /@annually fires at the expected local times/);
|
||||
assert.match(
|
||||
result.stdout,
|
||||
/@annually fires at the expected local times/,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const tz of process.env.QL_MACRO_TEST_TZ ? [process.env.QL_MACRO_TEST_TZ] : []) {
|
||||
for (const tz of process.env.QL_MACRO_TEST_TZ
|
||||
? [process.env.QL_MACRO_TEST_TZ]
|
||||
: []) {
|
||||
for (const [macro, start, next] of [
|
||||
['@annually', [2026, 11, 31, 23, 59, 59], [[2027, 0, 1, 0, 0, 0], [2028, 0, 1, 0, 0, 0]]],
|
||||
['@midnight', [2026, 8, 27, 23, 59, 59], [[2026, 8, 28, 0, 0, 0], [2026, 8, 29, 0, 0, 0]]],
|
||||
['@minutely', [2026, 8, 27, 12, 34, 59], [[2026, 8, 27, 12, 35, 0], [2026, 8, 27, 12, 36, 0]]],
|
||||
[
|
||||
'@annually',
|
||||
[2026, 11, 31, 23, 59, 59],
|
||||
[
|
||||
[2027, 0, 1, 0, 0, 0],
|
||||
[2028, 0, 1, 0, 0, 0],
|
||||
],
|
||||
],
|
||||
[
|
||||
'@midnight',
|
||||
[2026, 8, 27, 23, 59, 59],
|
||||
[
|
||||
[2026, 8, 28, 0, 0, 0],
|
||||
[2026, 8, 29, 0, 0, 0],
|
||||
],
|
||||
],
|
||||
[
|
||||
'@minutely',
|
||||
[2026, 8, 27, 12, 34, 59],
|
||||
[
|
||||
[2026, 8, 27, 12, 35, 0],
|
||||
[2026, 8, 27, 12, 36, 0],
|
||||
],
|
||||
],
|
||||
]) {
|
||||
test(`${macro} fires at the expected local times in ${tz}`, async (t) => {
|
||||
const previousTZ = process.env.TZ;
|
||||
process.env.TZ = tz;
|
||||
t.after(() => { if (previousTZ === undefined) delete process.env.TZ; else process.env.TZ = previousTZ; });
|
||||
t.mock.timers.enable({ apis: ['Date', 'setTimeout', 'setInterval'], now: new Date(...start) });
|
||||
t.after(() => {
|
||||
if (previousTZ === undefined) delete process.env.TZ;
|
||||
else process.env.TZ = previousTZ;
|
||||
});
|
||||
t.mock.timers.enable({
|
||||
apis: ['Date', 'setTimeout', 'setInterval'],
|
||||
now: new Date(...start),
|
||||
});
|
||||
const expected = next.map((parts) => new Date(...parts).getTime());
|
||||
const actual = [];
|
||||
assert.equal(isValidCronSchedule(` ${macro} `), true);
|
||||
const job = createCronJob(macro, (date) => actual.push(date.getTime()), {
|
||||
name: macro, logger: { warn() {}, error() {} },
|
||||
name: macro,
|
||||
logger: { warn() {}, error() {} },
|
||||
});
|
||||
t.after(() => job.cancel());
|
||||
for (const time of expected) {
|
||||
@@ -48,7 +85,15 @@ for (const tz of process.env.QL_MACRO_TEST_TZ ? [process.env.QL_MACRO_TEST_TZ] :
|
||||
}
|
||||
|
||||
test('new aliases do not enable unknown macros or raw parser extensions', () => {
|
||||
for (const schedule of ['@annuallyx', '@midnightx', '@minutelyx', '@secondly', '@reboot', 'H * * * *', '0 /5 * * * *']) {
|
||||
for (const schedule of [
|
||||
'@annuallyx',
|
||||
'@midnightx',
|
||||
'@minutelyx',
|
||||
'@secondly',
|
||||
'@reboot',
|
||||
'H * * * *',
|
||||
'0 /5 * * * *',
|
||||
]) {
|
||||
assert.equal(isValidCronSchedule(schedule), false, schedule);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user