mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-01-26 16:39:47 +00:00
Add advanced menu on job to allow user to do things like make a job as stopped if the status ever gets hung
This commit is contained in:
26
ui/src/app/api/jobs/[jobID]/mark_stopped/route.ts
Normal file
26
ui/src/app/api/jobs/[jobID]/mark_stopped/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: { jobID: string } }) {
|
||||
const { jobID } = await params;
|
||||
|
||||
const job = await prisma.job.findUnique({
|
||||
where: { id: jobID },
|
||||
});
|
||||
|
||||
// update job status to 'running'
|
||||
await prisma.job.update({
|
||||
where: { id: jobID },
|
||||
data: {
|
||||
stop: true,
|
||||
status: 'stopped',
|
||||
info: 'Job stopped',
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Job ${jobID} marked as stopped`);
|
||||
|
||||
return NextResponse.json(job);
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import Link from 'next/link';
|
||||
import { Eye, Trash2, Pen, Play, Pause } from 'lucide-react';
|
||||
import { Eye, Trash2, Pen, Play, Pause, Cog, NotebookPen } from 'lucide-react';
|
||||
import { Button } from '@headlessui/react';
|
||||
import { openConfirm } from '@/components/ConfirmModal';
|
||||
import { Job } from '@prisma/client';
|
||||
import { startJob, stopJob, deleteJob, getAvaliableJobActions } from '@/utils/jobs';
|
||||
import { startJob, stopJob, deleteJob, getAvaliableJobActions, markJobAsStopped } from '@/utils/jobs';
|
||||
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react';
|
||||
|
||||
interface JobActionBarProps {
|
||||
job: Job;
|
||||
@@ -90,6 +91,34 @@ export default function JobActionBar({ job, onRefresh, afterDelete, className, h
|
||||
>
|
||||
<Trash2 />
|
||||
</Button>
|
||||
<div className="border-r border-1 border-gray-700 ml-2 inline"></div>
|
||||
<Menu>
|
||||
<MenuButton className={'ml-2'}>
|
||||
<Cog />
|
||||
</MenuButton>
|
||||
<MenuItems anchor="bottom" className="bg-gray-900 border border-gray-700 rounded shadow-lg w-48 px-4 py-2 mt-4">
|
||||
<MenuItem>
|
||||
<div
|
||||
className="cursor-pointer"
|
||||
onClick={() => {
|
||||
let message = `Are you sure you want to mark this job as stopped? This will set the job status to 'stopped' if the status is hung. Only do this if you are 100% sure the job is stopped. This will NOT stop the job.`;
|
||||
openConfirm({
|
||||
title: 'Mark Job as Stopped',
|
||||
message: message,
|
||||
type: 'warning',
|
||||
confirmText: 'Mark as Stopped',
|
||||
onConfirm: async () => {
|
||||
await markJobAsStopped(job.id);
|
||||
onRefresh && onRefresh();
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
Mark as Stopped
|
||||
</div>
|
||||
</MenuItem>
|
||||
</MenuItems>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,22 @@ export const deleteJob = (jobID: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const markJobAsStopped = (jobID: string) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
apiClient
|
||||
.get(`/api/jobs/${jobID}/mark_stopped`)
|
||||
.then(res => res.data)
|
||||
.then(data => {
|
||||
console.log('Job marked as stopped:', data);
|
||||
resolve();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error marking job as stopped:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const getJobConfig = (job: Job) => {
|
||||
return JSON.parse(job.job_config) as JobConfig;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user