feat(ST-1111.2): add ClaudeJob status API mappers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5274e1ee1a
commit
a1b1f695d9
1 changed files with 32 additions and 0 deletions
32
lib/job-status.ts
Normal file
32
lib/job-status.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import type { ClaudeJobStatus } from '@prisma/client'
|
||||
|
||||
const JOB_DB_TO_API = {
|
||||
QUEUED: 'queued',
|
||||
CLAIMED: 'claimed',
|
||||
RUNNING: 'running',
|
||||
DONE: 'done',
|
||||
FAILED: 'failed',
|
||||
CANCELLED: 'cancelled',
|
||||
} as const satisfies Record<ClaudeJobStatus, string>
|
||||
|
||||
const JOB_API_TO_DB: Record<string, ClaudeJobStatus> = {
|
||||
queued: 'QUEUED',
|
||||
claimed: 'CLAIMED',
|
||||
running: 'RUNNING',
|
||||
done: 'DONE',
|
||||
failed: 'FAILED',
|
||||
cancelled: 'CANCELLED',
|
||||
}
|
||||
|
||||
export type ClaudeJobStatusApi = typeof JOB_DB_TO_API[ClaudeJobStatus]
|
||||
|
||||
export function jobStatusToApi(s: ClaudeJobStatus): ClaudeJobStatusApi {
|
||||
return JOB_DB_TO_API[s]
|
||||
}
|
||||
|
||||
export function jobStatusFromApi(s: string): ClaudeJobStatus | null {
|
||||
return JOB_API_TO_DB[s.toLowerCase()] ?? null
|
||||
}
|
||||
|
||||
export const JOB_STATUS_API_VALUES = Object.values(JOB_DB_TO_API)
|
||||
export const ACTIVE_JOB_STATUSES: ClaudeJobStatus[] = ['QUEUED', 'CLAIMED', 'RUNNING']
|
||||
Loading…
Add table
Add a link
Reference in a new issue