@@ -25,6 +25,7 @@ import (
2525 "encoding/json"
2626 "log"
2727 "sync"
28+ "fmt"
2829
2930 "github.com/NethServer/ns8-core/core/agent/models"
3031 "github.com/go-redis/redis/v8"
@@ -137,3 +138,26 @@ func runCancelTask(rdb *redis.Client, task *models.Task, cancelFuncMap map[strin
137138 }
138139 log .Printf ("task/%s/%s: action \" %s\" status is \" %s\" (%d) at step %s" , agentPrefix , task .ID , task .Action , actionDescriptor .Status , exitCode , lastStep )
139140}
141+
142+ func rejectAction (rdb * redis.Client , actionCtx context.Context , task * models.Task ) {
143+ progressChannel := "progress/" + agentPrefix + "/task/" + task .ID
144+ outputKey := "task/" + agentPrefix + "/" + task .ID + "/output"
145+ errorKey := "task/" + agentPrefix + "/" + task .ID + "/error"
146+ exitCodeKey := "task/" + agentPrefix + "/" + task .ID + "/exit_code"
147+ actionDescriptor := models.Processor {Status : "pending" }
148+ publishStatus (rdb , progressChannel , actionDescriptor ) // pending status
149+ actionOutput := ""
150+ actionError := fmt .Sprintf ("Agent is busy. Action %s rejected!\n " , task .Action )
151+ exitCode := 11
152+ actionDescriptor .Status = "aborted"
153+ log .Printf (SD_ERR + "Agent is busy. Action %s rejected!" , task .Action )
154+ rdb .TxPipelined (ctx , func (pipe redis.Pipeliner ) error {
155+ // Publish the action response
156+ pipe .Set (ctx , outputKey , actionOutput , taskExpireDuration )
157+ pipe .Set (ctx , errorKey , actionError , taskExpireDuration )
158+ pipe .Set (ctx , exitCodeKey , exitCode , taskExpireDuration )
159+ pipe .Expire (ctx , "task/" + agentPrefix + "/" + task .ID + "/context" , taskExpireDuration )
160+ publishStatus (pipe , progressChannel , actionDescriptor ) // aborted status
161+ return nil
162+ })
163+ }
0 commit comments