mirror of
https://github.com/whyour/qinglong.git
synced 2026-11-30 16:27:21 +08:00
feat: harden cron execution recovery and expose scheduling diagnostics
Reconcile scheduled and system cron triggers, isolate concurrent executions and retain verifiable exit statistics across restarts. Add paged task history, log and script browsing, dashboard timing details and regression coverage.
This commit is contained in:
1 parent
3b6a873520
commit
8a9e70e90b
166 files changed
+18942
-1800
No files matched your search
@@ -24,11 +24,11 @@ exports.verifyAccountMaintenance = async function verifyAccountMaintenance(
|
||||
assert.equal(result.status, 0, `${action} failed: ${result.stderr}`);
|
||||
assert.equal(JSON.parse(result.stdout).data.completed, true);
|
||||
};
|
||||
const login = async () => {
|
||||
const login = async (password = credentials.password) => {
|
||||
const response = await fetch('http://127.0.0.1:5700/api/user/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(credentials),
|
||||
body: JSON.stringify({ ...credentials, password }),
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
return response.json();
|
||||
@@ -36,18 +36,23 @@ exports.verifyAccountMaintenance = async function verifyAccountMaintenance(
|
||||
local('resetname', credentials.username);
|
||||
local('resetpwd', credentials.password);
|
||||
assert.equal((await login()).code, 200, 'New credentials were not saved');
|
||||
await api('system/auth/reset', 'PUT', { retries: 4 });
|
||||
assert.notEqual(
|
||||
const incorrect = randomUUID();
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
assert.equal((await login(incorrect)).code, 400, 'Expected a rejected password before throttling');
|
||||
}
|
||||
assert.equal(
|
||||
(await login()).code,
|
||||
200,
|
||||
410,
|
||||
'Fixture failed to activate login limit',
|
||||
);
|
||||
local('resetlet');
|
||||
assert.equal((await login()).code, 200, 'Login limit was not cleared');
|
||||
await api('system/auth/reset', 'PUT', { twoFactorActivated: true });
|
||||
assert.notEqual(
|
||||
const session = await login();
|
||||
assert.equal(session.code, 200, 'Login limit was not cleared');
|
||||
assert.ok(session.data.token, 'Fresh owner session required');
|
||||
await api('system/auth/reset', 'PUT', { twoFactorActivated: true }, session.data.token);
|
||||
assert.equal(
|
||||
(await login()).code,
|
||||
200,
|
||||
420,
|
||||
'Fixture failed to activate second factor',
|
||||
);
|
||||
local('resettfa');
|
||||
|
||||
@@ -2,7 +2,8 @@ const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs/promises');
|
||||
const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
const { spawn, spawnSync } = require('node:child_process');
|
||||
const { once } = require('node:events');
|
||||
|
||||
exports.verifyOperator = async function verifyOperator(api) {
|
||||
const ql = path.join(os.homedir(), 'bin/ql');
|
||||
@@ -26,12 +27,18 @@ exports.verifyOperator = async function verifyOperator(api) {
|
||||
schedule: '0 0 1 1 *',
|
||||
})
|
||||
).data;
|
||||
const child = spawn('sleep', ['60']);
|
||||
const ended = once(child, 'exit');
|
||||
const start = Math.floor(Date.now() / 1000);
|
||||
try {
|
||||
await api('crons/status', 'PUT', {
|
||||
ids: [task.id],
|
||||
status: '0',
|
||||
pid: String(child.pid),
|
||||
last_execution_time: start,
|
||||
log_path: 'cli-retention/2000-01-01-kept.log',
|
||||
});
|
||||
assert.equal((await api(`crons/${task.id}`)).data.log_path, 'cli-retention/2000-01-01-kept.log');
|
||||
const result = invoke(['rmlog', '7']);
|
||||
assert.ok(result.removed.includes('cli-retention/2000-01-01-unused.log'));
|
||||
assert.ok(result.retained.includes('cli-retention/2000-01-01-kept.log'));
|
||||
@@ -41,6 +48,8 @@ exports.verifyOperator = async function verifyOperator(api) {
|
||||
'referenced',
|
||||
);
|
||||
} finally {
|
||||
child.kill();
|
||||
await ended;
|
||||
await api('crons', 'DELETE', [task.id]);
|
||||
}
|
||||
const service = invoke(['reload']);
|
||||
|
||||
@@ -16,12 +16,12 @@ let restoreEntrypoints;
|
||||
);
|
||||
const base = 'http://127.0.0.1:5700';
|
||||
let token;
|
||||
async function api(endpoint, method = 'GET', body) {
|
||||
async function api(endpoint, method = 'GET', body, sessionToken = token) {
|
||||
const response = await fetch(`${base}/api/${endpoint}`, {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||
...(sessionToken ? { Authorization: `Bearer ${sessionToken}` } : {}),
|
||||
},
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
signal: AbortSignal.timeout(10000),
|
||||
|
||||
Reference in new issue
Block a user