Repository navigation
API: return the activity id from POST /services/{uuid}/restart and expose its status/output #11904
lgnap
started this conversation in
Improvement Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
POST /api/v1/services/{uuid}/restart?latest=true(added in #5881) is the API twin of the UI's "Pull latest images and restart". It works, but the caller gets nothing back except:{"message": "Service restarting request queued."}There is no way to find out afterwards whether the restart succeeded, whether
docker compose pullactually fetched a new image, or what the job printed:GET /api/v1/deploymentsstays[]before, during and after the restart — a service restart is not an application deployment, so it never shows up there (verified on v4.x).GET /api/v1/services/{uuid}/logsreturns the containers' stdout, not the restart job output.The output does exist: the job is a
Spatie\Activitylogactivity, and the UI shows it live in the activity monitor. It is just not reachable through the API.Use case
An automation (in my case a small dispatcher fed by Diun registry notifications) calls
restart?latest=truewhenever an image tag gets a new digest. Today it can only pollstatuson the service and guess "starting → running:healthy" means it worked; it cannot tell "Downloaded newer image" from "Image is up to date", nor report a failed pull. Any CI/CD or GitOps tooling driving services through the API hits the same wall.Proposal
Two small changes, both following code that already exists in the codebase:
1. Return the activity id from the restart endpoint.
The UI already does this synchronously:
app/Livewire/Project/Service/Heading.phpcallsStartService::run(...)and gets theActivityback (remote_process()creates the activity immediately and only queues the SSH execution). The API instead usesRestartService::dispatch(...)inServicesController::action_restart, so the activity does not exist yet when the response is built.Calling
RestartService::run()/StartService::run()the way the UI does would let the endpoint answer:{"message": "Service restarting request queued.", "activity_id": 459}(
StartServicestill returns quickly since the actual command runs in the queuedRunRemoteProcess.) The same could apply to/startand/stop.2. Expose the activity status/output.
GET /api/v1/services/{uuid}/activities/{activity_id}, modelled on the existingGET /databases/{uuid}/imports/{activity_id}(HandlesDatabaseImportsApi::showDatabaseImport), which already returns exactly the needed shape:{ "id": 459, "status": "finished", "exit_code": 0, "output": "Saved configuration files ...\nPulling ...\nStarting service.\n...", "created_at": "...", "updated_at": "...", "finished_at": "..." }Scoped by
properties->team_idandproperties->type_uuid = service uuid, like the import lookup, so a token can only read activities of its own team's services.Why not something else
status: works for "is it back up", not for "did anything change" or "did the pull fail".Happy to open a PR against
nextif this direction is acceptable.All reactions