This commit is contained in:
pb
2024-08-28 14:03:48 +02:00
parent 7206de35a8
commit a69ecc4ab5
6 changed files with 28 additions and 21 deletions

View File

@@ -9,7 +9,7 @@ import (
workflow_execution "cloud.o-forge.io/core/oc-lib/models/workflow_execution"
)
var Bookings = ScheduledBooking{Bookings: map[string]*workflow_execution.WorkflowExecution{}}
var Bookings = ScheduledBooking{Bookings: []*workflow_execution.WorkflowExecution{}}
type ExecutionManager struct{}
@@ -21,11 +21,12 @@ func (em *ExecutionManager) RetrieveNextExecutions() {
logger.Debug().Msg("New loop")
Bookings.Mu.Lock()
if len(Bookings.Bookings) > 0 {
for k, v := range Bookings.Bookings {
if v.ExecDate.Before(time.Now().UTC()) {
logger.Info().Msg("Will execute " + k + " soon")
go em.executeBooking(v)
delete(Bookings.Bookings, k)
bookings := Bookings.Bookings
for i := len(bookings) - 1; i >= 0; i-- {
if bookings[i].ExecDate.Before(time.Now().UTC()) {
logger.Info().Msg("Will execute " + bookings[i].UUID + " soon")
go em.executeBooking(bookings[i])
Bookings.Bookings = append(bookings[:i], bookings[i+1:]...)
}
}
}