feat: show today's failed tasks from dashboard

Add a failure list with task names, commands, accumulated failure counts and latest log links. Keep recovered and deleted tasks visible in today's statistics.

Fixes #3065
This commit is contained in:
whyour
2026-09-05 17:03:31 +08:00
parent 5f6049d80a
commit be2580d0e8
6 changed files with 303 additions and 3 deletions
+37
View File
@@ -107,6 +107,43 @@ export default (app: Router) => {
},
);
route.get(
'/failures',
async (req: Request, res: Response, next: NextFunction) => {
try {
const rows = (await CrontabStatModel.findAll({
attributes: ['ref_id', [fn('SUM', col('fail_count')), 'fail_count']],
where: { date: dayjs().format('YYYY-MM-DD'), fail_count: { [Op.gt]: 0 } },
group: ['ref_id'],
order: [[fn('SUM', col('fail_count')), 'DESC'], ['ref_id', 'ASC']],
raw: true,
})) as any[];
const crons = rows.length > 0 ? await CrontabModel.findAll({
attributes: ['id', 'name', 'command'],
where: { id: { [Op.in]: rows.map((row) => Number(row.ref_id)) } },
raw: true,
}) : [];
const cronMap = new Map(crons.map((cron) => [cron.id, cron]));
res.send({
code: 200,
data: rows.map((row) => {
const id = Number(row.ref_id);
const cron = cronMap.get(id);
return {
id,
name: cron?.name || cron?.command || tf('任务#%s', id),
command: cron?.command || '',
failCount: Number(row.fail_count),
deleted: !cron,
};
}),
});
} catch (e) {
next(e);
}
},
);
route.get(
'/trend',
async (req: Request, res: Response, next: NextFunction) => {