changed how we store upcoming executions from slice to map

This commit is contained in:
pb
2025-05-20 20:06:48 +02:00
parent bcc024caef
commit defdcf4264
3 changed files with 12 additions and 23 deletions

View File

@@ -22,11 +22,11 @@ func (em *ExecutionManager) RetrieveNextExecutions() {
Executions.Mu.Lock()
if len(Executions.Execs) > 0 {
executions := Executions.Execs
for i := len(executions) - 1; i >= 0; i-- {
if executions[i].ExecDate.Before(time.Now().UTC()) {
logger.Info().Msg("Will execute " + executions[i].UUID + " soon")
go em.executeExecution(executions[i])
Executions.Execs = append(executions[:i], executions[i+1:]...)
for execId, exec := range executions {
if exec.ExecDate.Before(time.Now().UTC()) {
logger.Info().Msg("Will execute " + execId + " soon")
go em.executeExecution(&exec)
delete(executions,execId)
}
}
}

View File

@@ -17,20 +17,14 @@ import (
)
type ScheduledExecution struct {
Execs []*workflow_execution.WorkflowExecution
Execs map[string]workflow_execution.WorkflowExecution
Mu sync.Mutex
}
func (sb *ScheduledExecution) DeleteSchedules(workflow_id string) {
toNotDelete := []*workflow_execution.WorkflowExecution{}
for _, b := range sb.Execs {
if b.WorkflowID != workflow_id {
toNotDelete = append(toNotDelete, b)
}
}
func (sb *ScheduledExecution) DeleteSchedules(uuid string) {
Executions.Mu.Lock()
defer Executions.Mu.Unlock()
sb.Execs = toNotDelete
delete(sb.Execs,uuid)
}
func (sb *ScheduledExecution) AddSchedules(new_executions []*workflow_execution.WorkflowExecution, logger zerolog.Logger) {
@@ -39,17 +33,16 @@ func (sb *ScheduledExecution) AddSchedules(new_executions []*workflow_execution.
for _, exec := range new_executions {
fmt.Println("Adding "+exec.UUID, !sb.execIsSet(exec))
if !sb.execIsSet(exec) {
sb.Execs = append(sb.Execs, exec)
sb.Execs[exec.UUID] = *exec
}
}
}
func (sb *ScheduledExecution) execIsSet(exec *workflow_execution.WorkflowExecution) bool {
for _, b := range sb.Execs {
if b.Equals(exec) {
return true
}
if _, ok := sb.Execs[exec.UUID]; ok{
return true
}
return false
}