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:
whyour committed 2026-11-22 12:24:29 +08:00
1 parent 77ece406ac
commit c5458596c8
346 files changed
+32133 -11556

No files matched your search

+36 -11
View File
@@ -3,11 +3,18 @@ import { readFileSync } from 'fs';
import path from 'path';
function read(file: string): string {
try { return readFileSync(file, 'utf8').trim(); } catch { return ''; }
try {
return readFileSync(file, 'utf8').trim();
} catch {
return '';
}
}
// Walk ancestors too: a nested cgroup can inherit a tighter parent quota.
export function containerResources(readValue = read, platform = process.platform) {
export function containerResources(
readValue = read,
platform = process.platform,
) {
const hostCpus = os.cpus().length;
const hostMemory = os.totalmem();
let cpus = hostCpus;
@@ -22,17 +29,25 @@ export function containerResources(readValue = read, platform = process.platform
const unified = !match[1];
for (const kind of ['cpu', 'memory', 'cpuset']) {
if (!unified && !controllers.includes(kind)) continue;
const roots = unified ? ['/sys/fs/cgroup'] : [...new Set([kind, match[1]].map(k => '/sys/fs/cgroup/' + k))];
const roots = unified
? ['/sys/fs/cgroup']
: [...new Set([kind, match[1]].map((k) => '/sys/fs/cgroup/' + k))];
for (const root of roots) {
let dir = path.join(root, path.normalize(match[2]));
while (dir === root || dir.startsWith(root + '/')) {
const value = (file: string) => readValue(path.join(dir, file));
if (kind === 'cpu') {
const [quota, period] = (unified ? value('cpu.max').split(/\s+/) :
[value('cpu.cfs_quota_us'), value('cpu.cfs_period_us')]).map(Number);
if (quota > 0 && period > 0) cpus = Math.min(cpus, quota / period);
const [quota, period] = (
unified
? value('cpu.max').split(/\s+/)
: [value('cpu.cfs_quota_us'), value('cpu.cfs_period_us')]
).map(Number);
if (quota > 0 && period > 0)
cpus = Math.min(cpus, quota / period);
} else if (kind === 'cpuset') {
const set = value(unified ? 'cpuset.cpus.effective' : 'cpuset.cpus');
const set = value(
unified ? 'cpuset.cpus.effective' : 'cpuset.cpus',
);
if (/^\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*$/.test(set)) {
const count = set.split(',').reduce((n, range) => {
const [lo, hi] = range.split('-').map(Number);
@@ -41,9 +56,13 @@ export function containerResources(readValue = read, platform = process.platform
if (count > 0) cpus = Math.min(cpus, count);
}
} else {
const limit = Number(value(unified ? 'memory.max' : 'memory.limit_in_bytes'));
const limit = Number(
value(unified ? 'memory.max' : 'memory.limit_in_bytes'),
);
if (limit > 0 && limit <= memTotal) {
const usage = value(unified ? 'memory.current' : 'memory.usage_in_bytes');
const usage = value(
unified ? 'memory.current' : 'memory.usage_in_bytes',
);
if (usage && Number.isFinite(Number(usage))) {
memTotal = limit;
memFree = Math.max(0, limit - Number(usage));
@@ -57,6 +76,12 @@ export function containerResources(readValue = read, platform = process.platform
}
}
}
return { cpus, memTotal, memFree, hostCpus, hostMemory,
memUsagePercent: ((1 - memFree / memTotal) * 100).toFixed(1) };
return {
cpus,
memTotal,
memFree,
hostCpus,
hostMemory,
memUsagePercent: ((1 - memFree / memTotal) * 100).toFixed(1),
};
}