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.
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import { literal, FindOptions } from 'sequelize';
|
|
|
|
// Queue membership belongs to the trigger. Expose it for list/detail reads
|
|
// without writing it into the manual-run reservation used by the scheduler.
|
|
export const visibleStatus = literal(`CASE
|
|
WHEN EXISTS (SELECT 1 FROM CronTriggers WHERE cron_id = "Crontab"."id" AND state = 'running') THEN 0
|
|
WHEN "Crontab"."status" = 1 AND EXISTS (
|
|
SELECT 1 FROM CronTriggers WHERE cron_id = "Crontab"."id" AND state = 'queued'
|
|
) THEN 3
|
|
ELSE "Crontab"."status" END`);
|
|
export const visibleAttributes: FindOptions['attributes'] = {
|
|
exclude: ['status'],
|
|
include: [[visibleStatus, 'status']],
|
|
};
|
|
|
|
// Resolve status and log ownership in one SQLite snapshot. A running trigger
|
|
// can be visible before its shell has published the file for this execution.
|
|
const activeLogTrigger = `FROM CronTriggers WHERE cron_id = "Crontab"."id"
|
|
AND state = 'running' ORDER BY started_at DESC, rowid DESC LIMIT 1`;
|
|
export const logAttributes: FindOptions['attributes'] = [
|
|
'log_name',
|
|
[visibleStatus, 'status'],
|
|
[
|
|
literal(`CASE WHEN EXISTS (SELECT 1 ${activeLogTrigger})
|
|
THEN (SELECT log_path ${activeLogTrigger}) ELSE "Crontab"."log_path" END`),
|
|
'log_path',
|
|
],
|
|
[
|
|
literal(`CASE WHEN allow_multiple_instances = 1 THEN COALESCE(
|
|
(SELECT id ${activeLogTrigger}),
|
|
(SELECT id FROM CronTriggers WHERE cron_id = "Crontab"."id" AND state = 'queued'
|
|
ORDER BY observed_at DESC, rowid DESC LIMIT 1)
|
|
) END`),
|
|
'logTriggerId',
|
|
],
|
|
];
|