Skip to content

Commit

Permalink
Prevent agent deletion when it's still running tasks (#3377)
Browse files Browse the repository at this point in the history
It wont solve the underlying issues like
woodpecker-ci/autoscaler#50 completely, but
should be a first step in the correct direction.
  • Loading branch information
anbraten authored Feb 12, 2024
1 parent 5d3a503 commit 65d88be
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ func DeleteAgent(c *gin.Context) {
handleDBError(c, err)
return
}

// prevent deletion of agents with running tasks
info := server.Config.Services.Queue.Info(c)
for _, task := range info.Running {
if task.AgentID == agent.ID {
c.String(http.StatusConflict, "Agent has running tasks")
return
}
}

if err = _store.AgentDelete(agent); err != nil {
c.String(http.StatusInternalServerError, "Error deleting user. %s", err)
return
Expand Down

0 comments on commit 65d88be

Please sign in to comment.