{{ message }}
feat(agent): Run deployment and service actions as streamed jobs#163
Merged
Conversation
Start, stop, restart and rebuild for both whole deployments and single services previously ran as one synchronous request whose compose output was returned only on completion, so the UI could show nothing but a spinner and the result was lost on a page reload. These actions now run as background jobs that return a job id immediately. Compose output streams line by line over a websocket and is also buffered so the status stays queryable, letting the result survive a reload. One action runs at a time per deployment, and per service within a deployment, so two different services can act concurrently while the same target cannot. Finished jobs are kept briefly in memory and are not retained across an agent restart.
| func (j *ActionJob) appendLine(line string) { | ||
| j.mu.Lock() | ||
| j.lines = append(j.lines, line) | ||
| for _, c := range j.subscribers { |
There was a problem hiding this comment.
When a subscriber channel is full, the line is dropped silently. While acceptable for 'live' updates, it might be safer to use a slightly larger buffer or a non-blocking check with a counter to log if users are consistently falling behind.
Suggested change
| for _, c := range j.subscribers { | |
| + for _, c := range j.subscribers { | |
| + select { | |
| + case c <- line: | |
| + default: | |
| + } | |
| + } |
Comment on lines
+357
to
+362
| scan := func(r io.Reader) { | ||
| defer wg.Done() | ||
| sc := bufio.NewScanner(r) | ||
| // Image pull/build progress lines can be long; raise the per-line cap. | ||
| sc.Buffer(make([]byte, 0, 64*1024), 1024*1024) | ||
| for sc.Scan() { |
There was a problem hiding this comment.
Using a single scanner for both stdout and stderr with a shared mutex to update the combined buffer is correct, but there is a risk of a very long line (e.g., binary output or large build logs) causing the scanner to fail. The buffer increase to 1MB is good, but sc.Err() should be checked after the loop to detect if a line was skipped because it exceeded the buffer.
Suggested change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #150.
Start/stop/restart/rebuild for a whole deployment, and for a single service, were synchronous: compose output came back only on completion, so the UI could show nothing but a spinner and the result was lost on reload.
These actions now run as background jobs. The endpoint returns a job id immediately, compose output streams line by line over a websocket (authenticated with the same first-message handshake as the terminal endpoints), and the output is buffered so the job status stays queryable and survives a page reload. One action runs at a time per deployment, and per service within a deployment, so different services can act concurrently while the same target is rejected. Finished jobs are kept briefly in memory and are not retained across an agent restart, which the page-reload requirement does not need.
Service actions go through a single
POST .../services/:service/jobtaking the action in the body, rather than a route per action.Concurrency was checked under
go test -racefor the job and streaming paths; the e2e helpers now enqueue and poll to keep their existing synchronous behaviour.