-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathrun.ts
More file actions
87 lines (77 loc) · 2.79 KB
/
run.ts
File metadata and controls
87 lines (77 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { get as _get } from 'lodash';
import { StatusIndicatorProps } from '@cloudscape-design/components';
import { capitalize } from 'libs';
import { IModelExtended } from '../pages/Models/List/types';
export const getStatusIconType = (
status: IRun['status'] | TJobStatus,
terminationReason: string | null | undefined,
): StatusIndicatorProps['type'] => {
if (terminationReason === 'interrupted_by_no_capacity') {
return 'stopped';
}
switch (status) {
case 'failed':
return 'error';
case 'aborted':
case 'terminated':
case 'done':
return 'stopped';
case 'running':
return 'success';
case 'terminating':
case 'pulling':
case 'provisioning':
return 'in-progress';
case 'submitted':
case 'pending':
return 'pending';
default:
console.error(new Error('Undefined run status'));
}
};
export const getStatusIconColor = (
status: IRun['status'] | TJobStatus,
terminationReason: string | null | undefined,
): StatusIndicatorProps.Color | undefined => {
if (terminationReason === 'failed_to_start_due_to_no_capacity' || terminationReason === 'interrupted_by_no_capacity') {
return 'yellow';
}
switch (status) {
case 'pulling':
return 'green';
case 'aborted':
return 'yellow';
default:
return undefined;
}
};
export const getRunStatusMessage = (run: IRun): string => {
if (run.latest_job_submission?.status_message) {
return capitalize(run.latest_job_submission.status_message);
} else {
return capitalize(run.status);
}
};
export const getRunError = (run: IRun): string | null => {
const error = run.error ?? run.latest_job_submission?.error ?? null;
return error ? capitalize(error) : null;
};
export const getExtendedModelFromRun = (run: IRun): IModelExtended | null => {
if (!run?.service?.model) return null;
return {
...(run.service?.model ?? {}),
id: run.id,
project_name: run.project_name,
run_name: run?.run_spec.run_name ?? 'No run name',
user: run.user,
resources: run.latest_job_submission?.job_provisioning_data?.instance_type?.resources?.description ?? null,
price: run.latest_job_submission?.job_provisioning_data?.price ?? null,
submitted_at: run.submitted_at,
repository: getRepoNameFromRun(run),
backend: run.latest_job_submission?.job_provisioning_data?.backend ?? null,
region: run.latest_job_submission?.job_provisioning_data?.region ?? null,
};
};
export const getRepoNameFromRun = (run: IRun): string => {
return _get(run.run_spec.repo_data, 'repo_name', _get(run.run_spec.repo_data, 'repo_dir', '-'));
};