mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-02-26 15:23:57 +00:00
Added controls to the jobs table
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import { JobConfig } from '@/types';
|
||||
import { Job } from '@prisma/client';
|
||||
|
||||
export const startJob = (jobID: string) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
fetch(`/api/jobs/${jobID}/start`)
|
||||
@@ -27,3 +30,36 @@ export const stopJob = (jobID: string) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteJob = (jobID: string) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
fetch(`/api/jobs/${jobID}/delete`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
console.log('Job deleted:', data);
|
||||
resolve();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error deleting job:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const getJobConfig = (job: Job) => {
|
||||
return JSON.parse(job.job_config) as JobConfig;
|
||||
};
|
||||
|
||||
export const getAvaliableJobActions = (job: Job) => {
|
||||
const jobConfig = getJobConfig(job);
|
||||
const isStopping = job.stop && job.status === 'running';
|
||||
const canDelete = ['completed', 'stopped', 'error'].includes(job.status) && !isStopping;
|
||||
const canEdit = ['completed', 'stopped', 'error'].includes(job.status) && !isStopping;
|
||||
const canStop = job.status === 'running' && !isStopping;
|
||||
let canStart = ['stopped', 'error'].includes(job.status) && !isStopping;
|
||||
// can resume if more steps were added
|
||||
if (job.status === 'completed' && jobConfig.config.process[0].train.steps > job.step && !isStopping) {
|
||||
canStart = true;
|
||||
}
|
||||
return { canDelete, canEdit, canStop, canStart };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user