Add caching to active job pull
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { isMac } from '@/helpers/basic';
|
||||
import { cached } from '@/server/apiCache';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
@@ -32,6 +33,17 @@ export async function GET(request: Request) {
|
||||
}
|
||||
if (only_active === 'true') {
|
||||
where.status = { in: ['running', 'queued', 'stopping'] };
|
||||
const jobs = await cached(
|
||||
'jobs-active',
|
||||
() =>
|
||||
prisma.job.findMany({
|
||||
where,
|
||||
orderBy: { created_at: 'desc' },
|
||||
}),
|
||||
5000,
|
||||
{ job_type },
|
||||
);
|
||||
return NextResponse.json({ jobs: jobs });
|
||||
}
|
||||
|
||||
const jobs = await prisma.job.findMany({
|
||||
@@ -52,16 +64,16 @@ export async function POST(request: Request) {
|
||||
let gpu_ids: string = body.gpu_ids;
|
||||
|
||||
if (isMac()) {
|
||||
gpu_ids = "mps";
|
||||
gpu_ids = 'mps';
|
||||
}
|
||||
|
||||
const extra: any = {};
|
||||
if ("job_ref" in body) {
|
||||
extra["job_ref"] = body.job_ref;
|
||||
if ('job_ref' in body) {
|
||||
extra['job_ref'] = body.job_ref;
|
||||
}
|
||||
|
||||
if ("job_type" in body) {
|
||||
extra["job_type"] = body.job_type;
|
||||
if ('job_type' in body) {
|
||||
extra['job_type'] = body.job_type;
|
||||
}
|
||||
|
||||
if (id) {
|
||||
|
||||
Reference in New Issue
Block a user