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 { isValidCronSchedule } = require('../../back/shared/cronSchedule');
|
||||
const { createCronJob } = require('../../back/shared/cronScheduler');
|
||||
const {
|
||||
isValidCronSchedule,
|
||||
} = require('../../back/cron/scheduling/cronSchedule');
|
||||
const { createCronJob } = require('../../back/cron/scheduling/cronScheduler');
|
||||
const legacy = require('../fixtures/legacy-cron.json');
|
||||
const logger = { warn() {}, error() {} };
|
||||
const flush = () => new Promise(setImmediate);
|
||||
@@ -10,7 +12,11 @@ test('validation preserves legacy syntax except the explicitly added macros', ()
|
||||
const addedMacros = new Set(['@annually', '@midnight', '@minutely']);
|
||||
assert.ok(legacy.validation.length > 250);
|
||||
for (const { schedule, accepted } of legacy.validation) {
|
||||
assert.equal(isValidCronSchedule(schedule), accepted || addedMacros.has(schedule), schedule);
|
||||
assert.equal(
|
||||
isValidCronSchedule(schedule),
|
||||
accepted || addedMacros.has(schedule),
|
||||
schedule,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,10 +24,20 @@ for (const sample of legacy.times) {
|
||||
test(`calendar compatibility: ${sample.schedule} from ${sample.currentDate}`, async (t) => {
|
||||
const previousTZ = process.env.TZ;
|
||||
process.env.TZ = 'UTC';
|
||||
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(sample.currentDate) });
|
||||
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(sample.currentDate),
|
||||
});
|
||||
const actual = [];
|
||||
const job = createCronJob(sample.schedule, (date) => actual.push(date.toISOString()), { name: 'calendar', logger });
|
||||
const job = createCronJob(
|
||||
sample.schedule,
|
||||
(date) => actual.push(date.toISOString()),
|
||||
{ name: 'calendar', logger },
|
||||
);
|
||||
t.after(() => job.cancel());
|
||||
for (const expected of sample.next) {
|
||||
t.mock.timers.tick(new Date(expected).getTime() - Date.now());
|
||||
@@ -32,13 +48,22 @@ for (const sample of legacy.times) {
|
||||
}
|
||||
|
||||
test('late callbacks catch up exactly once and cancellation destroys native tasks', async (t) => {
|
||||
t.mock.timers.enable({ apis: ['Date', 'setTimeout', 'setInterval'], now: new Date('2026-09-27T00:00:00Z') });
|
||||
t.mock.timers.enable({
|
||||
apis: ['Date', 'setTimeout', 'setInterval'],
|
||||
now: new Date('2026-09-27T00:00:00Z'),
|
||||
});
|
||||
const native = require('node-cron');
|
||||
const before = native.getTasks().size;
|
||||
const dates = [], warnings = [];
|
||||
const job = createCronJob('* * * * * *', (date) => dates.push(date.getTime()), {
|
||||
name: 'late', logger: { warn: (...args) => warnings.push(args), error() {} },
|
||||
});
|
||||
const dates = [],
|
||||
warnings = [];
|
||||
const job = createCronJob(
|
||||
'* * * * * *',
|
||||
(date) => dates.push(date.getTime()),
|
||||
{
|
||||
name: 'late',
|
||||
logger: { warn: (...args) => warnings.push(args), error() {} },
|
||||
},
|
||||
);
|
||||
t.after(() => job.cancel());
|
||||
t.mock.timers.tick(8000);
|
||||
await flush();
|
||||
@@ -53,12 +78,23 @@ test('late callbacks catch up exactly once and cancellation destroys native task
|
||||
});
|
||||
|
||||
test('callback rejection is logged and future executions continue', async (t) => {
|
||||
t.mock.timers.enable({ apis: ['Date', 'setTimeout', 'setInterval'], now: new Date('2026-09-27T00:00:00Z') });
|
||||
t.mock.timers.enable({
|
||||
apis: ['Date', 'setTimeout', 'setInterval'],
|
||||
now: new Date('2026-09-27T00:00:00Z'),
|
||||
});
|
||||
const errors = [];
|
||||
let count = 0;
|
||||
const job = createCronJob('* * * * * *', async () => { count++; throw Error('callback failed'); }, {
|
||||
name: 'failure', logger: { warn() {}, error: (...args) => errors.push(args) },
|
||||
});
|
||||
const job = createCronJob(
|
||||
'* * * * * *',
|
||||
async () => {
|
||||
count++;
|
||||
throw Error('callback failed');
|
||||
},
|
||||
{
|
||||
name: 'failure',
|
||||
logger: { warn() {}, error: (...args) => errors.push(args) },
|
||||
},
|
||||
);
|
||||
t.after(() => job.cancel());
|
||||
t.mock.timers.tick(1000);
|
||||
await flush();
|
||||
|
||||
Reference in new issue
Block a user