added reload group tasks
parent
18b7d63363
commit
2ebeeb20ad
|
@ -48,7 +48,14 @@
|
||||||
"onFinish": "nextStep",
|
"onFinish": "nextStep",
|
||||||
"undoPossible": false,
|
"undoPossible": false,
|
||||||
"scriptPath": "test2.py",
|
"scriptPath": "test2.py",
|
||||||
"parameters": [],
|
"parameters": [
|
||||||
|
{
|
||||||
|
"parameterName": "kundenname",
|
||||||
|
"type": "text",
|
||||||
|
"displayName": "Name des Kunden",
|
||||||
|
"global": true
|
||||||
|
}
|
||||||
|
],
|
||||||
"feedback": ""
|
"feedback": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
|
|
||||||
var root = "./groupTasks/groups/"
|
var root = "./groupTasks/groups/"
|
||||||
|
|
||||||
func ReadGroups() {
|
func LoadGroups(category string) {
|
||||||
entries, err := os.ReadDir(root)
|
entries, err := os.ReadDir(root)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,9 +26,13 @@ func ReadGroups() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, entry := range entries {
|
if category != "" {
|
||||||
log.Info().Msgf("Entry: %s", entry.Name())
|
cache.RemoveAllCategoryGroupsByCategory(category)
|
||||||
|
}
|
||||||
|
|
||||||
|
var updatedGroups []structs.Group
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
files, err := os.ReadDir(root + entry.Name())
|
files, err := os.ReadDir(root + entry.Name())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -37,8 +41,6 @@ func ReadGroups() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
log.Info().Msgf("File: %s", file.Name())
|
|
||||||
|
|
||||||
if file.Name() == "index.json" {
|
if file.Name() == "index.json" {
|
||||||
content, err := os.ReadFile(root + entry.Name() + "/index.json")
|
content, err := os.ReadFile(root + entry.Name() + "/index.json")
|
||||||
|
|
||||||
|
@ -53,12 +55,27 @@ func ReadGroups() {
|
||||||
|
|
||||||
group.Id = entry.Name()
|
group.Id = entry.Name()
|
||||||
|
|
||||||
log.Info().Msgf("Group: %s", group)
|
if category == "" || group.Category == category {
|
||||||
|
|
||||||
cache.AddCategoryGroup(group)
|
cache.AddCategoryGroup(group)
|
||||||
|
|
||||||
|
updatedGroups = append(updatedGroups, group)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if category != "" {
|
||||||
|
socketclients.BroadcastMessage(structs.SendSocketMessage{
|
||||||
|
Cmd: utils.SendCmdGroupTasksReloaded,
|
||||||
|
Body: struct {
|
||||||
|
Category string
|
||||||
|
UpdatedGroups []structs.Group
|
||||||
|
}{
|
||||||
|
Category: category,
|
||||||
|
UpdatedGroups: updatedGroups,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -83,13 +100,8 @@ type InputParameters struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunGroupTask(args RunGroupTaskArgs) {
|
func RunGroupTask(args RunGroupTaskArgs) {
|
||||||
log.Debug().Msgf("global input: %v", args.GlobalInputs)
|
|
||||||
|
|
||||||
categoryGroup := GetCategoryGroupTaskByCategoryAndGroupId(args.Category, args.GroupId)
|
categoryGroup := GetCategoryGroupTaskByCategoryAndGroupId(args.Category, args.GroupId)
|
||||||
|
|
||||||
log.Debug().Msgf("RunGroupTask %s", categoryGroup)
|
|
||||||
log.Debug().Msgf("script path %s", root+categoryGroup.Id+"/"+categoryGroup.Tasks[args.Step-1].ScriptPath)
|
|
||||||
|
|
||||||
groupTaskStep := structs.GroupTaskSteps{
|
groupTaskStep := structs.GroupTaskSteps{
|
||||||
GroupTasksId: args.GroupTaskId,
|
GroupTasksId: args.GroupTaskId,
|
||||||
Step: args.Step,
|
Step: args.Step,
|
||||||
|
@ -122,28 +134,19 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
||||||
var globalInputParameters []InputParameters
|
var globalInputParameters []InputParameters
|
||||||
|
|
||||||
if len(args.GlobalInputs) > 0 { // global inputs given in args because the group task was just created
|
if len(args.GlobalInputs) > 0 { // global inputs given in args because the group task was just created
|
||||||
log.Info().Msgf("global inputs given %s", args.GlobalInputs)
|
|
||||||
|
|
||||||
if err := json.Unmarshal([]byte(args.GlobalInputs), &globalInputParameters); err != nil {
|
if err := json.Unmarshal([]byte(args.GlobalInputs), &globalInputParameters); err != nil {
|
||||||
log.Error().Msgf("err unmarshalling global inputs %s", err.Error())
|
log.Error().Msgf("err unmarshalling global inputs %s", err.Error())
|
||||||
}
|
}
|
||||||
} else { // global inputs not given in args - fetch it from the database
|
} else { // global inputs not given in args - fetch it from the database
|
||||||
log.Info().Msgf("global inputs not given in args %s", dbGroupTask.GlobalInputs)
|
|
||||||
|
|
||||||
if err := json.Unmarshal([]byte(dbGroupTask.GlobalInputs), &globalInputParameters); err != nil {
|
if err := json.Unmarshal([]byte(dbGroupTask.GlobalInputs), &globalInputParameters); err != nil {
|
||||||
log.Error().Msgf("err unmarshalling global inputs %s", err.Error())
|
log.Error().Msgf("err unmarshalling global inputs %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// task parameters
|
// task parameters
|
||||||
log.Info().Msgf("unmarshalled global inputs %s", globalInputParameters)
|
|
||||||
log.Info().Msgf("task parameters %s", categoryGroup.Tasks[args.Step-1].Parameters)
|
|
||||||
|
|
||||||
commandArgs := []string{root + categoryGroup.Id + "/" + categoryGroup.Tasks[args.Step-1].ScriptPath}
|
commandArgs := []string{root + categoryGroup.Id + "/" + categoryGroup.Tasks[args.Step-1].ScriptPath}
|
||||||
|
|
||||||
if len(categoryGroup.Tasks[args.Step-1].Parameters) != 0 && len(args.TaskParameters) == 0 {
|
if len(categoryGroup.Tasks[args.Step-1].Parameters) != 0 && len(args.TaskParameters) == 0 {
|
||||||
log.Error().Msg("task parameters not specified")
|
|
||||||
|
|
||||||
updateGroupTask(groupTaskStep.GroupTasksId, structs.GroupTasks{
|
updateGroupTask(groupTaskStep.GroupTasksId, structs.GroupTasks{
|
||||||
Status: structs.GroupTasksStatusInputRequired,
|
Status: structs.GroupTasksStatusInputRequired,
|
||||||
})
|
})
|
||||||
|
@ -159,14 +162,10 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
||||||
log.Error().Msgf("err unmarshalling task parameter inputs %s", err.Error())
|
log.Error().Msgf("err unmarshalling task parameter inputs %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Msgf("task parameters %s", taskParameterInputs)
|
|
||||||
|
|
||||||
for _, taskParameterInput := range taskParameterInputs {
|
for _, taskParameterInput := range taskParameterInputs {
|
||||||
//commandArgs = append(commandArgs, "--"+taskParameterInput.ParameterName)
|
//commandArgs = append(commandArgs, "--"+taskParameterInput.ParameterName)
|
||||||
commandArgs = append(commandArgs, taskParameterInput.Value)
|
commandArgs = append(commandArgs, taskParameterInput.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Msgf("task parameters %s", commandArgs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute script
|
// execute script
|
||||||
|
@ -194,8 +193,6 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
||||||
|
|
||||||
updateGroupTaskSteps(groupTaskStep)
|
updateGroupTaskSteps(groupTaskStep)
|
||||||
|
|
||||||
log.Info().Msgf("run next task")
|
|
||||||
|
|
||||||
if int(args.Step) < len(categoryGroup.Tasks) {
|
if int(args.Step) < len(categoryGroup.Tasks) {
|
||||||
if groupTaskStep.Status == structs.GroupTasksStatusFailed {
|
if groupTaskStep.Status == structs.GroupTasksStatusFailed {
|
||||||
// set group task to failed
|
// set group task to failed
|
||||||
|
@ -210,8 +207,6 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
||||||
CurrentTasksStep: args.Step,
|
CurrentTasksStep: args.Step,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Debug().Msgf("RUN NEXT TASK %s", groupTaskStep)
|
|
||||||
|
|
||||||
// clear task parameters, because otherwise the next task would have the parameters from the previous task
|
// clear task parameters, because otherwise the next task would have the parameters from the previous task
|
||||||
args.TaskParameters = ""
|
args.TaskParameters = ""
|
||||||
|
|
||||||
|
@ -223,8 +218,6 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
||||||
Status: structs.GroupTasksStatusFinished,
|
Status: structs.GroupTasksStatusFinished,
|
||||||
EndedAt: time.Now(),
|
EndedAt: time.Now(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Info().Msg("SET TO FINISHED")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
main.go
2
main.go
|
@ -74,7 +74,7 @@ func main() {
|
||||||
return fiber.ErrUpgradeRequired
|
return fiber.ErrUpgradeRequired
|
||||||
})
|
})
|
||||||
|
|
||||||
grouptasks.ReadGroups()
|
grouptasks.LoadGroups("")
|
||||||
|
|
||||||
go socketserver.RunHub()
|
go socketserver.RunHub()
|
||||||
socketserver.WebSocketServer(app)
|
socketserver.WebSocketServer(app)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"janex/admin-dashboard-backend/modules/structs"
|
"janex/admin-dashboard-backend/modules/structs"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,6 +29,28 @@ func AddCategoryGroup(group structs.Group) {
|
||||||
CategoryGroups = append(CategoryGroups, categoryGroup)
|
CategoryGroups = append(CategoryGroups, categoryGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RemoveAllCategoryGroupsByCategory(category string) {
|
||||||
|
for index, categoryGroup := range GetCategoryGroups() {
|
||||||
|
if categoryGroup.Category == category {
|
||||||
|
cgMu.Lock()
|
||||||
|
defer cgMu.Unlock()
|
||||||
|
|
||||||
|
CategoryGroups = append(CategoryGroups[:index], CategoryGroups[index+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCategoryGroupsSorted() []structs.CategoryGroup {
|
||||||
|
categoryGroups := GetCategoryGroups()
|
||||||
|
|
||||||
|
cgMu.Lock()
|
||||||
|
defer cgMu.Unlock()
|
||||||
|
|
||||||
|
sort.SliceStable(categoryGroups, func(i, j int) bool { return categoryGroups[i].Category < categoryGroups[j].Category })
|
||||||
|
|
||||||
|
return categoryGroups
|
||||||
|
}
|
||||||
|
|
||||||
func GetCategoryGroups() []structs.CategoryGroup {
|
func GetCategoryGroups() []structs.CategoryGroup {
|
||||||
cgMu.RLock()
|
cgMu.RLock()
|
||||||
defer cgMu.RUnlock()
|
defer cgMu.RUnlock()
|
||||||
|
|
|
@ -22,6 +22,8 @@ const (
|
||||||
SentCmdNewGroupTaskStep = 4
|
SentCmdNewGroupTaskStep = 4
|
||||||
SentCmdUpdateGroupTaskStep = 5
|
SentCmdUpdateGroupTaskStep = 5
|
||||||
SentCmdUpdateGroupTask = 6
|
SentCmdUpdateGroupTask = 6
|
||||||
|
SentCmdReloadingGroupTasks = 7
|
||||||
|
SendCmdGroupTasksReloaded = 8
|
||||||
)
|
)
|
||||||
|
|
||||||
// commands received from web clients
|
// commands received from web clients
|
||||||
|
@ -29,6 +31,7 @@ const (
|
||||||
ReceivedCmdStartGroupTasks = 1
|
ReceivedCmdStartGroupTasks = 1
|
||||||
ReceivedCmdTaskFailedTryAgainRunTaskStep = 2
|
ReceivedCmdTaskFailedTryAgainRunTaskStep = 2
|
||||||
ReceivedCmdTaskContinueTaskStep = 3
|
ReceivedCmdTaskContinueTaskStep = 3
|
||||||
|
ReceivedCmdReloadGroupTasks = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -52,7 +52,7 @@ func RunHub() {
|
||||||
Username: user.Username,
|
Username: user.Username,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
},
|
},
|
||||||
CategoryGroups: cache.CategoryGroups,
|
CategoryGroups: cache.GetCategoryGroupsSorted(),
|
||||||
GroupTasks: grouptasks.GetAllGroupTasks(),
|
GroupTasks: grouptasks.GetAllGroupTasks(),
|
||||||
GroupTasksSteps: grouptasks.GetAllGroupTasksSteps(),
|
GroupTasksSteps: grouptasks.GetAllGroupTasksSteps(),
|
||||||
},
|
},
|
||||||
|
@ -134,8 +134,6 @@ func RunHub() {
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case utils.ReceivedCmdTaskContinueTaskStep:
|
case utils.ReceivedCmdTaskContinueTaskStep:
|
||||||
log.Info().Msgf("task continue task %s", receivedMessage.Body)
|
|
||||||
|
|
||||||
taskInputs := receivedMessage.Body["taskInputs"]
|
taskInputs := receivedMessage.Body["taskInputs"]
|
||||||
|
|
||||||
var taskInputsJsonString string
|
var taskInputsJsonString string
|
||||||
|
@ -162,6 +160,18 @@ func RunHub() {
|
||||||
})
|
})
|
||||||
|
|
||||||
break
|
break
|
||||||
|
case utils.ReceivedCmdReloadGroupTasks:
|
||||||
|
category := receivedMessage.Body["category"].(string)
|
||||||
|
|
||||||
|
socketclients.BroadcastMessage(structs.SendSocketMessage{
|
||||||
|
Cmd: utils.SentCmdReloadingGroupTasks,
|
||||||
|
Body: category,
|
||||||
|
})
|
||||||
|
|
||||||
|
grouptasks.LoadGroups(category)
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Error().Msgf("Received unknown message: %s", receivedMessage)
|
log.Error().Msgf("Received unknown message: %s", receivedMessage)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue