Prevent agent deletion when it's still running tasks (#3377)

It wont solve the underlying issues like
https://github.com/woodpecker-ci/autoscaler/issues/50 completely, but
should be a first step in the correct direction.
This commit is contained in:
Anbraten 2024-02-12 19:23:56 +01:00 committed by GitHub
parent 5d3a503f98
commit 65d88be523
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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