mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 17:56:30 +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
+51
-28
@@ -1,11 +1,11 @@
|
||||
import { ServerUnaryCall, sendUnaryData, status } from '@grpc/grpc-js';
|
||||
import { AddCronRequest, AddCronResponse } from '../protos/cron';
|
||||
import { createCronJob, CronJob } from '../shared/cronScheduler';
|
||||
import { isValidCronSchedule } from '../shared/cronSchedule';
|
||||
import { createCronJob, CronJob } from '../cron/scheduling/cronScheduler';
|
||||
import { isValidCronSchedule } from '../cron/scheduling/cronSchedule';
|
||||
import { scheduleStacks } from './data';
|
||||
import { latestMissedSlot } from '../shared/cronRecovery';
|
||||
import { slotId } from '../shared/triggerHistory';
|
||||
import { runCron } from '../shared/runCron';
|
||||
import { latestMissedSlot } from '../cron/scheduling/cronRecovery';
|
||||
import { slotId } from '../cron/history';
|
||||
import { runCron } from '../cron/execution/runCron';
|
||||
import Logger from '../loaders/logger';
|
||||
import { t, tf } from '../shared/i18n';
|
||||
|
||||
@@ -63,9 +63,15 @@ const addCron = (
|
||||
const recoveries: (() => Promise<void>)[] = [];
|
||||
try {
|
||||
for (const item of desired.values()) {
|
||||
const signature = JSON.stringify([item.schedule, item.command,
|
||||
(item.extra_schedules || []).map((s) => s.schedule), item.max_queue_wait || 0,
|
||||
!!item.skip_if_pending, item.catchup_seconds || 0, item.catchup_seconds || item.skip_if_pending ? item.recovery_from : 0]);
|
||||
const signature = JSON.stringify([
|
||||
item.schedule,
|
||||
item.command,
|
||||
(item.extra_schedules || []).map((s) => s.schedule),
|
||||
item.max_queue_wait || 0,
|
||||
!!item.skip_if_pending,
|
||||
item.catchup_seconds || 0,
|
||||
item.catchup_seconds || item.skip_if_pending ? item.recovery_from : 0,
|
||||
]);
|
||||
const current = scheduleStacks.get(item.id);
|
||||
if (current && definitions.get(current) === signature) continue;
|
||||
const jobs: CronJob[] = [];
|
||||
@@ -75,31 +81,44 @@ const addCron = (
|
||||
item.schedule,
|
||||
...(item.extra_schedules || []).map((x) => x.schedule),
|
||||
].entries()) {
|
||||
const fire = async (date: Date, source: 'node' | 'recovery' = 'node') => {
|
||||
const fire = async (
|
||||
date: Date,
|
||||
source: 'node' | 'recovery' = 'node',
|
||||
) => {
|
||||
const isCurrent = () => scheduleStacks.get(item.id) === jobs;
|
||||
if (!isCurrent()) return;
|
||||
await runCron(item.command, item, isCurrent, date && {
|
||||
id: slotId(item.id, ruleIndex, schedule, +date), time: +date, source,
|
||||
});
|
||||
await runCron(
|
||||
item.command,
|
||||
item,
|
||||
isCurrent,
|
||||
date && {
|
||||
id: slotId(item.id, ruleIndex, schedule, +date),
|
||||
time: +date,
|
||||
source,
|
||||
},
|
||||
);
|
||||
};
|
||||
if (call.request.replace && item.catchup_seconds && item.recovery_from) {
|
||||
if (
|
||||
call.request.replace &&
|
||||
item.catchup_seconds &&
|
||||
item.recovery_from
|
||||
) {
|
||||
recoveries.push(async () => {
|
||||
const now = Date.now();
|
||||
const since = Math.max(item.recovery_from!, now - item.catchup_seconds! * 1000);
|
||||
const since = Math.max(
|
||||
item.recovery_from!,
|
||||
now - item.catchup_seconds! * 1000,
|
||||
);
|
||||
const time = latestMissedSlot(schedule, since, now);
|
||||
if (time !== null) await fire(new Date(time), 'recovery');
|
||||
});
|
||||
}
|
||||
jobs.push(
|
||||
createCronJob(
|
||||
schedule,
|
||||
fire,
|
||||
{
|
||||
name: `${item.id}: ${item.name || ''}`,
|
||||
logger: Logger,
|
||||
start: false,
|
||||
},
|
||||
),
|
||||
createCronJob(schedule, fire, {
|
||||
name: `${item.id}: ${item.name || ''}`,
|
||||
logger: Logger,
|
||||
start: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -134,13 +153,17 @@ const addCron = (
|
||||
}
|
||||
|
||||
callback(null, null);
|
||||
for (const recover of recoveries) setImmediate(() => recover().catch((err) => Logger.error(String(err))));
|
||||
for (const recover of recoveries)
|
||||
setImmediate(() => recover().catch((err) => Logger.error(String(err))));
|
||||
};
|
||||
if (savePlan) {
|
||||
savePlan().then(activate).catch(error => {
|
||||
for (const jobs of prepared.values()) jobs.forEach(job => job.cancel());
|
||||
callback(error);
|
||||
});
|
||||
savePlan()
|
||||
.then(activate)
|
||||
.catch((error) => {
|
||||
for (const jobs of prepared.values())
|
||||
jobs.forEach((job) => job.cancel());
|
||||
callback(error);
|
||||
});
|
||||
} else activate();
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user