feat!(backend): unify script run and ad-hoc job run
ci-agent / build (push) Failing after 5m25s

This commit is contained in:
2026-04-05 04:10:59 +03:00
parent add1242b97
commit e5724f0611
4 changed files with 69 additions and 74 deletions
+29 -15
View File
@@ -72,35 +72,49 @@ func (h *JobsHandlers) AddJob(c *gin.Context) {
return
}
agent, ok := h.tracker.GetAgent(in.AgentID)
if !ok {
c.Status(http.StatusNotFound)
c.Error(fmt.Errorf("agent not found"))
return
}
command, err := resolveCommand(c, h.svc, in.InterpreterID, in.Command)
result, err := h.runCommand(c, in.AgentID, in.InterpreterID, in.Command, in.Stdin)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusCreated, result)
}
// runCommand resolves command, submits a job to the agent, and returns AddJobOut.
// Shared between jobs and scripts handlers.
func (h *JobsHandlers) runCommand(
c *gin.Context,
agentID string,
interpID int64,
command string,
stdin *string,
) (*AddJobOut, error) {
agent, ok := h.tracker.GetAgent(agentID)
if !ok {
return nil, fmt.Errorf("agent not found")
}
cmd, err := resolveCommand(c, h.svc, interpID, command)
if err != nil {
return nil, err
}
jid, err := agent.AddJob(models.JobForInsert{
Command: command,
Stdin: in.Stdin,
Command: cmd,
Stdin: stdin,
})
if err != nil {
c.Error(err)
return
return nil, err
}
waitURL := fmt.Sprintf("%s/api/v1/jobs/%d/wait", h.whereami, jid)
c.JSON(http.StatusCreated, AddJobOut{
return &AddJobOut{
ID: jid,
Command: command,
Command: cmd,
WaitURL: waitURL,
})
}, nil
}
// WaitJob waits for a submitted job to complete (long-poll).