mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
Share durable permits across manual, scheduled and recovered runs, prioritize short ready tasks with aging, and record global queue occupancy. Reduce launch, log polling, dashboard and SQLite overhead while preserving transactional receipts, cancellation, recovery and script hook compatibility. Keep ordinary CRUD in ORM and bound SQL on measured execution hot paths. Fix supervisor descendant tracking, asynchronous log draining, concurrent log directory creation, Linux fallback launches and snapshot clock rollback. Include regression coverage, SQL audits and evolution/review documentation. Validation: five review rounds; local full suite 1478 passed, 28 platform skips; dev suites 415 passed, no failures/skips; backend types and formatting passed.
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { executionModel } from '../../data/executionModels';
|
|
import { Op } from 'sequelize';
|
|
import type { ICron } from '../../protos/cron';
|
|
import { CrontabModel } from '../../data/cron';
|
|
import { slotId } from '../identity';
|
|
import { runCron } from '../execution/runCron';
|
|
|
|
// Accepted work is distinct from catching up timers missed while offline.
|
|
// Keep its identity and original queue deadline; never replay a bound command.
|
|
export async function resumeAcceptedCrons(item: ICron, current: () => boolean) {
|
|
const rows = await executionModel(
|
|
CrontabModel.sequelize!,
|
|
'CronTriggers',
|
|
).findAll({
|
|
attributes: ['id', 'scheduled_at', 'queued_at'],
|
|
where: {
|
|
cron_id: Number(item.id),
|
|
source: { [Op.in]: ['node', 'recovery'] },
|
|
state: 'skipped',
|
|
reason: 'restart',
|
|
resume_pending: 1,
|
|
started_at: null,
|
|
queued_at: { [Op.gte]: item.recovery_from || 0 },
|
|
},
|
|
order: [
|
|
['queued_at', 'ASC'],
|
|
['id', 'ASC'],
|
|
],
|
|
raw: true,
|
|
});
|
|
const rules = [
|
|
item.schedule,
|
|
...(item.extra_schedules || []).map((s) => s.schedule),
|
|
];
|
|
await Promise.all(
|
|
rows
|
|
.filter((row) =>
|
|
rules.some(
|
|
(rule, i) => slotId(item.id, i, rule, row.scheduled_at!) === row.id,
|
|
),
|
|
)
|
|
.map((row) =>
|
|
runCron(item.command, item, current, {
|
|
id: row.id,
|
|
time: row.scheduled_at!,
|
|
queuedAt: row.queued_at!,
|
|
source: 'recovery',
|
|
}),
|
|
),
|
|
);
|
|
}
|