1
0
Fork 0

add types for unknown jobs

This commit is contained in:
Sean Sube 2024-01-03 21:32:00 -06:00
parent 28fc2082c7
commit 5a48447585
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
3 changed files with 28 additions and 4 deletions

View File

@ -32,6 +32,7 @@ export function ImageHistory() {
case JobStatus.SUCCESS: case JobStatus.SUCCESS:
children.push([key, <ImageCard key={`history-${key}`} image={item.image} onDelete={removeHistory} />]); children.push([key, <ImageCard key={`history-${key}`} image={item.image} onDelete={removeHistory} />]);
break; break;
case JobStatus.UNKNOWN:
case JobStatus.FAILED: case JobStatus.FAILED:
children.push([key, <ErrorCard key={`history-${key}`} image={item.image} retry={item.retry} />]); children.push([key, <ErrorCard key={`history-${key}`} image={item.image} retry={item.retry} />]);
break; break;

View File

@ -10,10 +10,10 @@ import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow'; import { shallow } from 'zustand/shallow';
import { ClientContext, ConfigContext, OnnxState, StateContext } from '../../state/full.js'; import { ClientContext, ConfigContext, OnnxState, StateContext } from '../../state/full.js';
import { FailedJobResponse, RetryParams } from '../../types/api-v2.js'; import { FailedJobResponse, JobStatus, RetryParams, UnknownJobResponse } from '../../types/api-v2.js';
export interface ErrorCardProps { export interface ErrorCardProps {
image: FailedJobResponse; image: FailedJobResponse | UnknownJobResponse;
retry: Maybe<RetryParams>; retry: Maybe<RetryParams>;
} }
@ -54,7 +54,7 @@ export function ErrorCard(props: ErrorCardProps) {
<Alert severity='error'> <Alert severity='error'>
{t('loading.progress', image.steps)} {t('loading.progress', image.steps)}
<br /> <br />
{image.error} {getImageErrorReason(image)}
</Alert> </Alert>
<Stack direction='row' spacing={2}> <Stack direction='row' spacing={2}>
<Tooltip title={t('tooltip.retry')}> <Tooltip title={t('tooltip.retry')}>
@ -82,3 +82,11 @@ export function selectActions(state: OnnxState) {
removeHistory: state.removeHistory, removeHistory: state.removeHistory,
}; };
} }
export function getImageErrorReason(image: FailedJobResponse | UnknownJobResponse) {
if (image.status === JobStatus.FAILED) {
return image.error;
}
return image.reason;
}

View File

@ -62,6 +62,20 @@ export interface BaseJobResponse {
export interface CancelledJobResponse extends BaseJobResponse { export interface CancelledJobResponse extends BaseJobResponse {
status: JobStatus.CANCELLED; status: JobStatus.CANCELLED;
/**
* Error message to indicate if the job was cancelled by a client, admin, or the server.
*/
reason: string;
}
export interface UnknownJobResponse extends BaseJobResponse {
status: JobStatus.UNKNOWN;
/**
* Error message to indicate why the job was marked as unknown, if there are extenuating circumstances.
*/
reason: string;
} }
/** /**
@ -157,7 +171,8 @@ export type JobResponse
| PendingJobResponse | PendingJobResponse
| RunningJobResponse | RunningJobResponse
| FailedJobResponse | FailedJobResponse
| SuccessJobResponse; | SuccessJobResponse
| UnknownJobResponse;
/** /**
* Status response from the job endpoint, with parameters to retry the job if it fails. * Status response from the job endpoint, with parameters to retry the job if it fails.