Skip to content

Commit

Permalink
Add output to api
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuMoalic committed Mar 4, 2024
1 parent e45a2e1 commit 6397399
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 175 deletions.
166 changes: 45 additions & 121 deletions frontend/src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,17 @@ export enum ConnectionStatusEnum {
* * `SLOW` - SLOW
* * `NORMAL` - NORMAL
* * `FAST` - FAST
* * `UNDEF` - UNDEF
*/
export enum GpuPartitionEnum {
SLOW = 'SLOW',
NORMAL = 'NORMAL',
FAST = 'FAST'
FAST = 'FAST',
UNDEF = 'UNDEF'
}

export interface Gpus {
readonly id: number;
/**
* The speed of the GPU.
*
* * `SLOW` - SLOW
* * `NORMAL` - NORMAL
* * `FAST` - FAST
* @default "NORMAL"
*/
speed?: SpeedEnum;
/**
* The current status of the GPU.
*
* * `WAITING` - WAITING
* * `PENDING` - PENDING
* * `RESERVED` - RESERVED
* * `UNAVALIBLE` - UNAVALIBLE
* @default "WAITING"
*/
status?: GpusStatusEnum;
/** The associated node ID. */
node: number;
/**
Expand All @@ -65,6 +48,12 @@ export interface Gpus {
*/
uuid: string;
model: string;
/**
* * `SLOW` - SLOW
* * `NORMAL` - NORMAL
* * `FAST` - FAST
*/
speed?: SpeedEnum;
/**
* The utilization of the GPU (must be <= 100).
* @format int64
Expand All @@ -73,6 +62,13 @@ export interface Gpus {
*/
util: number;
is_running_amumax?: boolean;
/**
* * `RUNNING` - RUNNING
* * `PENDING` - PENDING
* * `RESERVED` - RESERVED
* * `UNAVAILABLE` - UNAVAILABLE
*/
status?: GpusStatusEnum;
/**
* The timestamp of the last update (read-only, auto-generated).
* @format date-time
Expand All @@ -81,16 +77,16 @@ export interface Gpus {
}

/**
* * `WAITING` - WAITING
* * `RUNNING` - RUNNING
* * `PENDING` - PENDING
* * `RESERVED` - RESERVED
* * `UNAVALIBLE` - UNAVALIBLE
* * `UNAVAILABLE` - UNAVAILABLE
*/
export enum GpusStatusEnum {
WAITING = 'WAITING',
RUNNING = 'RUNNING',
PENDING = 'PENDING',
RESERVED = 'RESERVED',
UNAVALIBLE = 'UNAVALIBLE'
UNAVAILABLE = 'UNAVAILABLE'
}

export interface Job {
Expand Down Expand Up @@ -121,6 +117,7 @@ export interface Job {
* * `SLOW` - SLOW
* * `NORMAL` - NORMAL
* * `FAST` - FAST
* * `UNDEF` - UNDEF
*/
gpu_partition?: GpuPartitionEnum;
/**
Expand All @@ -130,14 +127,11 @@ export interface Job {
*/
duration?: number;
/**
* * `WAITING` - WAITING
* * `PENDING` - PENDING
* * `FINISHED` - FINISHED
* * `INTERRUPTED` - INTERRUPTED
*/
status?: JobStatusEnum;
output?: string | null;
error?: string | null;
/** @maxLength 150 */
flags?: string | null;
/** @maxLength 150 */
Expand All @@ -147,19 +141,17 @@ export interface Job {
}

/**
* * `WAITING` - WAITING
* * `PENDING` - PENDING
* * `FINISHED` - FINISHED
* * `INTERRUPTED` - INTERRUPTED
*/
export enum JobStatusEnum {
WAITING = 'WAITING',
PENDING = 'PENDING',
FINISHED = 'FINISHED',
INTERRUPTED = 'INTERRUPTED'
}

export interface MS {
export interface ManagerSettings {
readonly id: number;
queue_watchdog?: boolean;
}
Expand All @@ -176,7 +168,6 @@ export interface Nodes {
*/
number_of_gpus: number;
/**
* * `WAITING` - WAITING
* * `PENDING` - PENDING
* * `RESERVED` - RESERVED
* * `UNAVAILABLE` - UNAVAILABLE
Expand All @@ -192,13 +183,11 @@ export interface Nodes {
}

/**
* * `WAITING` - WAITING
* * `PENDING` - PENDING
* * `RESERVED` - RESERVED
* * `UNAVAILABLE` - UNAVAILABLE
*/
export enum NodesStatusEnum {
WAITING = 'WAITING',
PENDING = 'PENDING',
RESERVED = 'RESERVED',
UNAVAILABLE = 'UNAVAILABLE'
Expand Down Expand Up @@ -232,6 +221,7 @@ export interface PatchedJob {
* * `SLOW` - SLOW
* * `NORMAL` - NORMAL
* * `FAST` - FAST
* * `UNDEF` - UNDEF
*/
gpu_partition?: GpuPartitionEnum;
/**
Expand All @@ -241,14 +231,11 @@ export interface PatchedJob {
*/
duration?: number;
/**
* * `WAITING` - WAITING
* * `PENDING` - PENDING
* * `FINISHED` - FINISHED
* * `INTERRUPTED` - INTERRUPTED
*/
status?: JobStatusEnum;
output?: string | null;
error?: string | null;
/** @maxLength 150 */
flags?: string | null;
/** @maxLength 150 */
Expand All @@ -257,7 +244,7 @@ export interface PatchedJob {
gpu?: number | null;
}

export interface PatchedMS {
export interface PatchedManagerSettings {
readonly id?: number;
queue_watchdog?: boolean;
}
Expand Down Expand Up @@ -300,6 +287,10 @@ export interface TokenRefresh {
refresh: string;
}

export interface Output {
output: string;
}

export type QueryParamsType = Record<string | number, any>;
export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;

Expand Down Expand Up @@ -708,32 +699,13 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
* No description
*
* @tags jobs
* @name JobsStartCreate
* @request POST:/api/jobs/{id}/start/
* @secure
*/
jobsStartCreate: (id: number, data: Job, params: RequestParams = {}) =>
this.request<Job, any>({
path: `/api/jobs/${id}/start/`,
method: 'POST',
body: data,
secure: true,
type: ContentType.Json,
format: 'json',
...params
}),

/**
* No description
*
* @tags manager-settings
* @name ManagerSettingsList
* @request GET:/api/manager-settings/
* @name JobsOutputRetrieve
* @request GET:/api/jobs/{id}/output/
* @secure
*/
managerSettingsList: (params: RequestParams = {}) =>
this.request<MS[], any>({
path: `/api/manager-settings/`,
jobsOutputRetrieve: (id: number, params: RequestParams = {}) =>
this.request<Output, any>({
path: `/api/jobs/${id}/output/`,
method: 'GET',
secure: true,
format: 'json',
Expand All @@ -743,14 +715,14 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
/**
* No description
*
* @tags manager-settings
* @name ManagerSettingsCreate
* @request POST:/api/manager-settings/
* @tags jobs
* @name JobsStartCreate
* @request POST:/api/jobs/{id}/start/
* @secure
*/
managerSettingsCreate: (data: MS, params: RequestParams = {}) =>
this.request<MS, any>({
path: `/api/manager-settings/`,
jobsStartCreate: (id: number, data: Job, params: RequestParams = {}) =>
this.request<Job, any>({
path: `/api/jobs/${id}/start/`,
method: 'POST',
body: data,
secure: true,
Expand All @@ -759,42 +731,6 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
...params
}),

/**
* No description
*
* @tags manager-settings
* @name ManagerSettingsRetrieve
* @request GET:/api/manager-settings/{id}/
* @secure
*/
managerSettingsRetrieve: (id: number, params: RequestParams = {}) =>
this.request<MS, any>({
path: `/api/manager-settings/${id}/`,
method: 'GET',
secure: true,
format: 'json',
...params
}),

/**
* No description
*
* @tags manager-settings
* @name ManagerSettingsUpdate
* @request PUT:/api/manager-settings/{id}/
* @secure
*/
managerSettingsUpdate: (id: number, data: MS, params: RequestParams = {}) =>
this.request<MS, any>({
path: `/api/manager-settings/${id}/`,
method: 'PUT',
body: data,
secure: true,
type: ContentType.Json,
format: 'json',
...params
}),

/**
* No description
*
Expand All @@ -803,8 +739,12 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
* @request PATCH:/api/manager-settings/{id}/
* @secure
*/
managerSettingsPartialUpdate: (id: number, data: PatchedMS, params: RequestParams = {}) =>
this.request<MS, any>({
managerSettingsPartialUpdate: (
id: number,
data: PatchedManagerSettings,
params: RequestParams = {}
) =>
this.request<ManagerSettings, any>({
path: `/api/manager-settings/${id}/`,
method: 'PATCH',
body: data,
Expand All @@ -814,22 +754,6 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
...params
}),

/**
* No description
*
* @tags manager-settings
* @name ManagerSettingsDestroy
* @request DELETE:/api/manager-settings/{id}/
* @secure
*/
managerSettingsDestroy: (id: number, params: RequestParams = {}) =>
this.request<void, any>({
path: `/api/manager-settings/${id}/`,
method: 'DELETE',
secure: true,
...params
}),

/**
* No description
*
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/api/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ export function sortItems(item_type: 'jobs' | 'nodes' | 'gpus'): void {
});
}

export function getJobOutput(job: Job): Promise<string> {
return new Promise((resolve, reject) => {
api.jobsOutputRetrieve(job.id, getRequestParams()).then(
(response) => {
resolve(response.data.output);
}
).catch(err => {
console.error(err);
reject(err);
});
});
}


export async function runJob(job: Job) {
api.jobsStartCreate(job.id, job, getRequestParams()).then(() => {
newToast(`Started job ${job.id}`, "green");
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/lib/Drawer/Output.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script lang="ts">
import { onMount } from 'svelte';
import type { Job } from '$api/Api';
import { getJobOutput } from '$api/Table';
export let job: Job;
import Prism from 'prismjs';
import 'prismjs/components/prism-go'; // Ensure the import path is correct
let output = '';
onMount(() => {
output = job.output || 'nope';
let output = 'waiting for output...';
onMount(async () => {
output = await getJobOutput(job);
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/Table/TableTitle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
<RefreshOutline
on:click={() => {
fetchItems('jobs');
fetchItems(item_type);
}}
class="ml-3 text-gray-500"
/>
Expand Down
2 changes: 1 addition & 1 deletion manager/manager/run_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self) -> None:

def find_gpu(self, partition):
gpu = Gpu.objects.filter(
status="WAITING",
status="PENDING",
# speed=partition #TEMPORARY DISABLED
).first()
if gpu is None:
Expand Down
Loading

0 comments on commit 6397399

Please sign in to comment.