Skip to content
Snippets Groups Projects
Commit 042fa91a authored by ml bonhomme's avatar ml bonhomme :bee:
Browse files

Entypescripten the Ponos API helpers

parent ff7826c6
No related branches found
No related tags found
1 merge request!1533Entypescripten the Ponos API helpers
import axios from 'axios'
import { unique } from '.'
/**
* @param {import('@/types').UUID} id Task ID
* @returns {Promise<Task>}
*/
export const retrieveTask = unique(async id => (await axios.get(`/task/${id}/from-agent/`)).data)
/**
* @param {import('@/types').UUID} id Task ID
* @param {Partial<Pick<Task, 'state'>>} payload Task attributes to update
* @returns {Promise<Pick<Task, 'id' | 'state'>>}
*/
export const updateTask = async (id, payload) => (await axios.patch(`/task/${id}/`, payload)).data
/**
* @param {import('@/types').UUID} id Task ID
* @returns {Promise<Artifact[]>}
*/
export const listArtifacts = unique(async id => (await axios.get(`/task/${id}/artifacts/`)).data)
// List Ponos agents with their status
export const listAgents = unique(async params => (await axios.get('/agents/', { params })).data)
// Retrieve a Ponos agent with its running tasks
export const retrieveAgent = unique(async id => (await axios.get(`/agent/${id}/`)).data)
// List Ponos farms
export const listFarms = unique(async params => (await axios.get('/farms/', { params })).data)
import axios from 'axios'
import { PageNumberPaginationParameters, unique } from '.'
import { PageNumberPagination, UUID } from '@/types'
import { AgentDetails, AgentState, Artifact, Farm, Task } from '@/types/ponos'
export const retrieveTask = unique(async (id: UUID): Promise<Task> => (await axios.get(`/task/${id}/from-agent/`)).data)
type TaskUpdatePayload = Partial<Pick<Task, 'state'>>
type TaskUpdateResponse = Pick<Task, 'id' | 'state'>
export const updateTask = async (id: UUID, payload: TaskUpdatePayload): Promise<TaskUpdateResponse> => (await axios.patch(`/task/${id}/`, payload)).data
export const listArtifacts = unique(async (id: UUID): Promise<Artifact[]> => (await axios.get(`/task/${id}/artifacts/`)).data)
// List Ponos agents with their status
export const listAgents = unique(async (params: PageNumberPaginationParameters): Promise<PageNumberPagination<AgentState>> => (await axios.get('/agents/', { params })).data)
// Retrieve a Ponos agent with its running tasks
export const retrieveAgent = unique(async (id: UUID): Promise<AgentDetails> => (await axios.get(`/agent/${id}/`)).data)
// List Ponos farms
export const listFarms = unique(async (params: PageNumberPaginationParameters): Promise<PageNumberPagination<Farm>> => (await axios.get('/farms/', { params })).data)
import { ProcessState, UUID } from "."
export interface Farm {
id: UUID
name: string
}
export interface GPU {
id: UUID
index: number
name: string
ram_total: number
}
export interface TaskLight {
id: UUID
run: number
depth: number
slug: string
state: ProcessState
parents: UUID[]
tags: string[]
shm_size: string
}
interface AgentLight {
id: UUID
farm: Farm
hostname: string
cpu_cores: number
cpu_frequency: number
ram_total: number
cpu_load: number | null
ram_load: number | null
last_ping: string
gpus: GPU[]
}
export interface AgentState extends AgentLight {
active: boolean
running_tasks_count: number
}
export interface AgentDetails extends AgentLight {
active: boolean
running_tasks: TaskLight[]
}
export interface Task extends TaskLight {
logs: string
full_log: string
agent: AgentLight | null
gpu: GPU | null
extra_files: Record<string, string>
}
export interface Artifact {
id: UUID
path: string
size: number
content_type: string
url: string
s3_put_url: string | null
created: string
updated: string
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment