fix(commander): missing job id on errors
ci-agent / build (push) Failing after 3m4s

This commit is contained in:
2026-04-04 19:32:00 +03:00
parent 81d8f71937
commit fe7e41e4af
2 changed files with 13 additions and 14 deletions
+9 -13
View File
@@ -10,15 +10,13 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
type CommandExecutor struct { type CommandExecutor struct{}
}
func (*CommandExecutor) Execute(command *proto.Command) (*proto.FinishedCommand, error) { func (*CommandExecutor) Execute(command *proto.Command) (fc *proto.FinishedCommand, err error) {
fc = new(proto.FinishedCommand)
fc.Id = command.Id
cmd := exec.Command(command.Command[0], command.Command[1:]...) cmd := exec.Command(command.Command[0], command.Command[1:]...)
var ( var stdin io.WriteCloser
stdin io.WriteCloser
err error
)
if command.Stdin != nil { if command.Stdin != nil {
stdin, err = cmd.StdinPipe() stdin, err = cmd.StdinPipe()
if err != nil { if err != nil {
@@ -56,10 +54,8 @@ func (*CommandExecutor) Execute(command *proto.Command) (*proto.FinishedCommand,
if err := eg.Wait(); err != nil { if err := eg.Wait(); err != nil {
return nil, err return nil, err
} }
return &proto.FinishedCommand{ fc.Status = int32(cmd.ProcessState.ExitCode())
Id: command.Id, fc.Stdout = stdoutbuf.String()
Status: int32(cmd.ProcessState.ExitCode()), fc.Stderr = stderrbuf.String()
Stdout: stdoutbuf.String(), return
Stderr: stderrbuf.String(),
}, nil
} }
+4 -1
View File
@@ -1,8 +1,11 @@
package handlers package handlers
import ( import (
"errors"
"fmt" "fmt"
"net/http" "net/http"
"os"
"os/exec"
"gitea.d3m0k1d.ru/d3m0k1d/HellreigN/backend/internal/grpcsrv/commander" "gitea.d3m0k1d.ru/d3m0k1d/HellreigN/backend/internal/grpcsrv/commander"
"gitea.d3m0k1d.ru/d3m0k1d/HellreigN/backend/internal/models" "gitea.d3m0k1d.ru/d3m0k1d/HellreigN/backend/internal/models"
@@ -74,7 +77,7 @@ func (self *JobsHandlers) AddJob(c *gin.Context) {
return err return err
} }
job, err := agent.WaitJob(jid) job, err := agent.WaitJob(jid)
if err != nil { if err != nil && !errors.Is(err, &exec.ExitError{}) {
return err return err
} }
c.JSON(http.StatusCreated, AddJobOut{ c.JSON(http.StatusCreated, AddJobOut{