mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-22 23:18:05 +03:00
fix: admin stash cron viewer is capped in a funny way (#1695)
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
SELECT_JOB_QUEUE,
|
||||
} from "#lib/db-formats/admin-jobs";
|
||||
import DB from "#services/pg/db";
|
||||
import { sql } from "kysely";
|
||||
|
||||
export const ADMIN_PAGE_SIZE = 50;
|
||||
|
||||
@@ -161,10 +162,34 @@ export function GetCronTasks(): Promise<Array<CronTask>> {
|
||||
.execute();
|
||||
}
|
||||
|
||||
export function GetCronTaskExecutions(limit = 100): Promise<Array<CronTaskExecution>> {
|
||||
return DB.selectFrom("cron_task_execution")
|
||||
.select(SELECT_CRON_TASK_EXECUTION)
|
||||
.orderBy("cron_task_execution.scheduled_at", "desc")
|
||||
.limit(limit)
|
||||
const CAP_PER_TASK_TYPE = 100;
|
||||
|
||||
export async function GetCronTaskExecutions(): Promise<Array<CronTaskExecution>> {
|
||||
const rows = await DB.with("ranked", (db) =>
|
||||
db
|
||||
.selectFrom("cron_task_execution")
|
||||
.select([
|
||||
...SELECT_CRON_TASK_EXECUTION,
|
||||
sql<number>`ROW_NUMBER() OVER (PARTITION BY cron_task_execution.task_id ORDER BY cron_task_execution.scheduled_at DESC)`.as(
|
||||
"rn",
|
||||
),
|
||||
])
|
||||
.where("cron_task_execution.scheduled_at", ">=", adminRecentSinceIso()),
|
||||
)
|
||||
.selectFrom("ranked")
|
||||
.select([
|
||||
"ranked.id",
|
||||
"ranked.task_id",
|
||||
"ranked.scheduled_at",
|
||||
"ranked.started_at",
|
||||
"ranked.completed_at",
|
||||
"ranked.status",
|
||||
"ranked.output",
|
||||
"ranked.error",
|
||||
])
|
||||
.where(sql<boolean>`ranked.rn <= ${sql.lit(CAP_PER_TASK_TYPE)}`)
|
||||
.orderBy("ranked.scheduled_at", "desc")
|
||||
.execute();
|
||||
|
||||
return rows as Array<CronTaskExecution>;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ API_V1_ROUTER.add("GET /admin/actions", withAdmin, async ({ input }) => {
|
||||
});
|
||||
|
||||
API_V1_ROUTER.add("GET /admin/cron-tasks", withAdmin, async () => {
|
||||
const [tasks, executions] = await Promise.all([GetCronTasks(), GetCronTaskExecutions(100)]);
|
||||
const [tasks, executions] = await Promise.all([GetCronTasks(), GetCronTaskExecutions()]);
|
||||
|
||||
return success("Done.", { executions, tasks });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user