-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathrun.ts
More file actions
116 lines (102 loc) · 3.74 KB
/
run.ts
File metadata and controls
116 lines (102 loc) · 3.74 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { get as _get } from 'lodash';
import { StatusIndicatorProps } from '@cloudscape-design/components';
import { capitalize } from 'libs';
import { formatResources } from 'libs/resources';
import { finishedRunStatuses } from '../pages/Runs/constants';
import { getJobProbesStatuses } from '../pages/Runs/Details/Jobs/List/helpers';
import { IModelExtended } from '../pages/Models/List/types';
export const getStatusIconType = (
status: IRun['status'] | TJobStatus,
terminationReason: string | null | undefined,
): StatusIndicatorProps['type'] => {
if (finishedRunStatuses.includes(status) && terminationReason === 'interrupted_by_no_capacity') {
return 'stopped';
}
switch (status) {
case 'failed':
return 'error';
case 'done':
return 'success';
case 'aborted':
case 'terminated':
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,
statusMessage: string,
): StatusIndicatorProps.Color | undefined => {
if (statusMessage === 'No fleets') {
return 'red';
}
if (terminationReason === 'failed_to_start_due_to_no_capacity' || terminationReason === 'interrupted_by_no_capacity') {
return 'yellow';
}
switch (status) {
case 'submitted':
case 'pending':
return 'blue';
case 'pulling':
return 'green';
case 'aborted':
return 'yellow';
case 'done':
return 'grey';
default:
return undefined;
}
};
export const getRunStatusMessage = (run: IRun): string => {
if (finishedRunStatuses.includes(run.status) && run.latest_job_submission?.status_message) {
return capitalize(run.latest_job_submission.status_message);
} else {
return capitalize(run.status_message || 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 getRunProbeStatuses = (run: IRun): StatusIndicatorProps.Type[] => {
const job = run.jobs[0];
if (!job) {
return [];
}
return getJobProbesStatuses(run.jobs[0]);
};
export const getRunPriority = (run: IRun): number | null => {
return run.run_spec.configuration?.priority ?? 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
? formatResources(run.latest_job_submission.job_provisioning_data.instance_type.resources)
: 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', '-'));
};