mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
perf(cron): share global concurrency budget and streamline execution
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.
This commit is contained in:
1 parent
cddabbaf0e
commit
2f01f756d7
74 files changed
+6891
-837
No files matched your search
@@ -0,0 +1,49 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { dashboardSnapshot } = require('../../back/shared/dashboardSnapshot');
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
test('a backwards wall clock cannot extend the display snapshot lifetime', async (t) => {
|
||||
let now = 100000;
|
||||
t.mock.method(Date, 'now', () => now);
|
||||
const db = {};
|
||||
let calls = 0;
|
||||
assert.equal(await dashboardSnapshot(db, 'today', async () => ++calls), 1);
|
||||
now -= 60000;
|
||||
await sleep(1100);
|
||||
assert.equal(await dashboardSnapshot(db, 'today', async () => ++calls), 2);
|
||||
});
|
||||
|
||||
test('eight viewers share one computation and a bounded snapshot; day/database changes and failures refresh', async () => {
|
||||
const db = {};
|
||||
let calls = 0,
|
||||
release;
|
||||
const compute = () => {
|
||||
calls++;
|
||||
return new Promise((r) => {
|
||||
release = r;
|
||||
});
|
||||
};
|
||||
const pending = Array.from({ length: 8 }, () =>
|
||||
dashboardSnapshot(db, 'today', compute),
|
||||
);
|
||||
await sleep(0);
|
||||
assert.equal(calls, 1);
|
||||
release({ count: 50000 });
|
||||
assert.deepEqual(await Promise.all(pending), Array(8).fill({ count: 50000 }));
|
||||
assert.deepEqual(
|
||||
await dashboardSnapshot(db, 'today', () => assert.fail('cache miss')),
|
||||
{ count: 50000 },
|
||||
);
|
||||
await sleep(1010);
|
||||
assert.equal(await dashboardSnapshot(db, 'today', async () => ++calls), 2);
|
||||
assert.equal(await dashboardSnapshot(db, 'tomorrow', async () => ++calls), 3);
|
||||
assert.equal(await dashboardSnapshot({}, 'tomorrow', async () => ++calls), 4);
|
||||
await assert.rejects(
|
||||
dashboardSnapshot(db, 'bad', async () => {
|
||||
throw Error('sqlite busy');
|
||||
}),
|
||||
/sqlite busy/,
|
||||
);
|
||||
assert.equal(await dashboardSnapshot(db, 'bad', async () => ++calls), 5);
|
||||
});
|
||||
Reference in new issue
Block a user