DiamondLightSource / blueapi

Apache License 2.0
6 stars 6 forks source link

Add a REST api endpoint to create a plan and run it #412

Open stan-dot opened 7 months ago

stan-dot commented 7 months ago

in order to champion delightful dev experience we should add a new POST endpoint as a thin wrapper around the logic for plan creation and plan execution. example

callumforrester commented 7 months ago

We can't allow uploading arbitrary code and executing it on the server for security reasons

DiamondJoseph commented 7 months ago

As above, but additionally

DiamondJoseph commented 7 months ago

We may have misread this as "POST a random .py file": is it intended to be that or just "an endpoint that combines


@app.post(
    "/tasks",
    response_model=TaskResponse,
    status_code=status.HTTP_201_CREATED,
)
def submit_task(

and

@app.put(
    "/worker/task",
    response_model=WorkerTask,
    responses={status.HTTP_409_CONFLICT: {"worker": "already active"}},
)
def update_task(

?

stan-dot commented 7 months ago

well yes, it's about the second one - what verification could run there? the second one would be suitable

callumforrester commented 6 months ago

The reason they are currently two endpoints is to allow clients to syncrhonise on the task ID

DiamondJoseph commented 6 months ago

To expand: we need the client to have the task ID before the task begins, in case the task completes almost instantly (e.g. a failed scan). Posting the initial task returns the task ID which is used as a temporary queue name in RabbitMQ, that the client would not be able to know anything until after the task has potentially failed. Then the client attempts to listen to the queue and it never receives any messages. The client times-out, assuming the task has locked up when actually the task failed prior.

stan-dot commented 6 months ago

what if we use a websocket connection instead of REST for stuff like this then? davidia already has a setup like that

stan-dot commented 1 month ago

The reason they are currently two endpoints is to allow clients to syncrhonise on the task ID

that does not exclude the option for this endpoint to exist for API debugging purposes