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.
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { createHash } from 'crypto';
|
|
|
|
export type AnomalyKind = 'missing' | 'skipped' | 'unconfirmed';
|
|
export interface ScheduleAnomaly {
|
|
task: number;
|
|
name?: string;
|
|
rule: string | null;
|
|
time: number | null;
|
|
source: 'node' | 'recovery' | 'system';
|
|
trigger: string | null;
|
|
observed: number | null;
|
|
reason: string | null;
|
|
logPath: string | null;
|
|
ruleIndex?: number;
|
|
}
|
|
|
|
// Keep only the requested page and the first page. If late evidence changes
|
|
// the result between requests, return the new first page instead of mixing scans.
|
|
export class AnomalyPage {
|
|
private hash = createHash('sha256');
|
|
private total = 0;
|
|
private first: ScheduleAnomaly[] = [];
|
|
private selected: ScheduleAnomaly[] = [];
|
|
static readonly size = 25;
|
|
|
|
constructor(
|
|
readonly kind: AnomalyKind,
|
|
private page: number,
|
|
private previous?: string,
|
|
) {}
|
|
|
|
add(row: ScheduleAnomaly) {
|
|
this.hash.update(JSON.stringify(row)).update('\n');
|
|
const page = Math.floor(this.total++ / AnomalyPage.size) + 1;
|
|
if (page === 1) this.first.push(row);
|
|
if (page === this.page) this.selected.push(row);
|
|
}
|
|
|
|
result() {
|
|
const revision = this.hash.digest('hex');
|
|
const changed = !!this.previous && revision !== this.previous;
|
|
const reset = changed || (this.page > 1 && !this.selected.length);
|
|
return {
|
|
rows: reset ? this.first : this.selected,
|
|
total: this.total,
|
|
page: reset ? 1 : this.page,
|
|
pageSize: AnomalyPage.size,
|
|
revision,
|
|
changed,
|
|
};
|
|
}
|
|
}
|