mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +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
@@ -10,19 +10,31 @@ test('startup closes interrupted instances without inventing exit codes or rewri
|
||||
logging: false,
|
||||
});
|
||||
t.after(() => db.close());
|
||||
const instances = db.define('Instance', {
|
||||
const instances = db.define('RunningInstance', {
|
||||
cron_id: DataTypes.INTEGER,
|
||||
pid: DataTypes.INTEGER,
|
||||
log_path: DataTypes.TEXT,
|
||||
status: DataTypes.INTEGER,
|
||||
started_at: DataTypes.INTEGER,
|
||||
finished_at: DataTypes.INTEGER,
|
||||
exit_code: DataTypes.INTEGER,
|
||||
});
|
||||
const crons = db.define('Crontab', { status: DataTypes.INTEGER, pid: DataTypes.INTEGER, queued_token: DataTypes.STRING, command: DataTypes.STRING });
|
||||
await db.sync();
|
||||
await db.transaction(tx => require('../../back/shared/triggerHistory').installTriggerHistory(db, tx));
|
||||
await instances.bulkCreate([
|
||||
{ id: 1, status: 0, started_at: 100 },
|
||||
{ id: 2, status: 1, started_at: 100, finished_at: 110, exit_code: 0 },
|
||||
{ id: 3, status: 2, started_at: 100, finished_at: 120, exit_code: 143 },
|
||||
{ id: 4, status: 3, started_at: 100, finished_at: 130, exit_code: 7 },
|
||||
]);
|
||||
const {TriggerHistory, systemOwner} = require('../../back/shared/triggerHistory');
|
||||
const history = new TriggerHistory(db);
|
||||
await crons.create({id: 9, status: 0, pid: process.pid, command: 'task live.sh'});
|
||||
await instances.create({id: 9, status: 0, started_at: 100});
|
||||
await db.query("INSERT INTO CronTriggers(id,cron_id,source,state,owner,instance_id,observed_at) VALUES ('live',9,'system','running',$owner,9,100)",
|
||||
{bind:{owner:systemOwner(process.pid)}});
|
||||
await history.interrupt('http');
|
||||
const systemConfig = { info: { lang: 'en-US' } };
|
||||
const startupEvents = [];
|
||||
const service = {
|
||||
@@ -40,7 +52,7 @@ test('startup closes interrupted instances without inventing exit codes or rewri
|
||||
'../services/user': class {},
|
||||
'../services/open': class {},
|
||||
'../data/cron': {
|
||||
CrontabModel: { update: async () => {}, findAll: async () => [] },
|
||||
CrontabModel: { sequelize: db, update: async () => {}, findAll: async () => [] },
|
||||
CrontabStatus: { idle: 1 },
|
||||
},
|
||||
'../data/dependence': {
|
||||
@@ -87,7 +99,9 @@ test('startup closes interrupted instances without inventing exit codes or rewri
|
||||
global.setTimeout = originalTimeout;
|
||||
}
|
||||
assert.deepEqual(startupEvents, ['environment', 'scheduler']);
|
||||
const rows = await instances.findAll({ order: [['id', 'ASC']], raw: true });
|
||||
assert.equal((await instances.findByPk(9)).status,0);
|
||||
assert.equal((await crons.findByPk(9)).pid,process.pid);
|
||||
const rows = await instances.findAll({ where:{id:[1,2,3,4]}, order: [['id', 'ASC']], raw: true });
|
||||
assert.equal(rows[0].status, 2);
|
||||
assert.ok(
|
||||
rows[0].finished_at >= before &&
|
||||
@@ -118,7 +132,7 @@ test('startup closes interrupted instances without inventing exit codes or rewri
|
||||
'environment', 'scheduler', 'environment', 'scheduler',
|
||||
]);
|
||||
assert.deepEqual(
|
||||
await instances.findAll({ order: [['id', 'ASC']], raw: true }),
|
||||
await instances.findAll({ where:{id:[1,2,3,4]}, order: [['id', 'ASC']], raw: true }),
|
||||
rows,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user