changed how we store upcoming executions from slice to map
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user