Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
| import { JobConfig, JobRecord } from '@/types'; | |
| import { apiClient } from '@/utils/api'; | |
| import { usingBrowserDb } from '@/utils/env'; | |
| import { deleteJobRecord } from '@/utils/storage/jobStorage'; | |
| export const startJob = async (jobID: string) => { | |
| if (usingBrowserDb) { | |
| throw new Error('Local jobs are not supported when using browser database mode.'); | |
| } | |
| await apiClient.get(`/api/jobs/${jobID}/start`).then(res => res.data); | |
| }; | |
| export const stopJob = async (jobID: string) => { | |
| if (usingBrowserDb) { | |
| throw new Error('Stopping jobs is not available when using browser database mode.'); | |
| } | |
| await apiClient.get(`/api/jobs/${jobID}/stop`).then(res => res.data); | |
| }; | |
| export const deleteJob = async (jobID: string) => { | |
| if (usingBrowserDb) { | |
| await deleteJobRecord(jobID); | |
| return; | |
| } | |
| await apiClient.get(`/api/jobs/${jobID}/delete`).then(res => res.data); | |
| }; | |
| export const getJobConfig = (job: JobRecord) => { | |
| return JSON.parse(job.job_config) as JobConfig; | |
| }; | |
| export const getAvaliableJobActions = (job: JobRecord) => { | |
| const jobConfig = getJobConfig(job); | |
| const isStopping = job.stop && job.status === 'running'; | |
| const editableStatuses = ['completed', 'stopped', 'error', 'submitted', 'pending']; | |
| const canDelete = editableStatuses.includes(job.status) && !isStopping; | |
| const canEdit = editableStatuses.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 }; | |
| }; | |
| export const getNumberOfSamples = (job: JobRecord) => { | |
| const jobConfig = getJobConfig(job); | |
| return jobConfig.config.process[0].sample?.prompts?.length || 0; | |
| }; | |
| export const getTotalSteps = (job: JobRecord) => { | |
| const jobConfig = getJobConfig(job); | |
| return jobConfig.config.process[0].train.steps; | |
| }; | |