From 65d88be52397dbfbb63306f93d95fc4c81828608 Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:23:56 +0100 Subject: [PATCH] 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. --- server/api/agent.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/api/agent.go b/server/api/agent.go index c327ffd70..5946e93a9 100644 --- a/server/api/agent.go +++ b/server/api/agent.go @@ -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