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