ries-lab / DECODE_Cloud_WorkerAPI

0 stars 0 forks source link

Update worker facing API endpoints #28

Open Haydnspass opened 1 year ago

Haydnspass commented 1 year ago
@app.get("/file/{file_id}")
async def file_get(file_id) -> str:
    # return presigned public URL
    match file_id:
        case "music":
            url = "http://212.183.159.230/5MB.zip"
        case "video":
            url = "http://212.183.159.230/10MB.zip"
        case "decode_file":
            url = "https://oc.embl.de/index.php/s/GzSbmU7pheHEdC0/download"
        case _:
            print(file_id)
            raise ValueError(f"Unknown file_id {file_id}")

    return url

class Job(BaseModel):
    job_id: str
    image: str
    image_version: str
    command: str | list[str] | None
    job_env: dict[str, str] | None
    files: dict[str, str]
    path_upload: str

@app.get("/job")
async def job_get() -> Job:
    return Job(
        job_id="a6",
        image="mock_decode",
        image_version="0.0.4",
        command=None,
        job_env={
            "JOB_ID": "a6"
        },
        files={
            # "config/music.mp3": "music",  # path / file_id
            # "config/video.mp3": "video",
            "data/decode.txt": "decode_file"
        },
        path_upload="output/",
    )

@app.post("/job/{job_id}/file")
async def job_file_post(job_id: str, file: UploadFile = File(...)):

    # put file
    p = Path("~/temp/decode_cloud/api").expanduser() / Path(file.filename).name

    print(f"Uploaded file for {job_id} with file {file.filename}, dumping it to {p}")
    with p.open("wb") as f:
        f.write(file.file.read())

    return {"filename": file.filename}

@app.get("/job/{job_id}/status")
async def job_status_get(job_id):
    return {"message": f"The job with ID {job_id}."}

class StatusBody(BaseModel):
    status_body: str | None

@app.put("/job/{job_id}/status")
async def job_status_put(
    job_id: str,
    status: Literal["running", "stopped", "error"],
    status_body: StatusBody | None = None,
):
    return {
        "job_id": job_id,
        "status": status,
        "status_body": status_body.status_body,
    }
Haydnspass commented 1 year ago

@nolan1999 Please edit the defaults as

    cpu_cores: int,
    memory: int,    
    env: str | None = None,
    gpu_model: str | None = None,
    gpu_archi: str | None = None,
    groups: list[str] | None = Query(None),
    limit: int = 1,
    older_than: int | None = None,
Haydnspass commented 1 year ago

please also add gpu_mem : int | None = None

Haydnspass commented 1 year ago

and the hostname which could be nice for logging / debugging