oc-schedulerd/daemons/execution_manager.go

55 lines
1.5 KiB
Go
Raw Normal View History

2024-07-11 18:25:40 +02:00
package daemons
2024-07-23 12:16:20 +02:00
import (
"oc-schedulerd/conf"
2024-07-29 15:45:32 +02:00
"os"
2024-07-23 12:16:20 +02:00
"time"
oclib "cloud.o-forge.io/core/oc-lib"
2024-07-23 12:16:20 +02:00
)
2024-07-11 18:25:40 +02:00
type ExecutionManager struct {
bookings ScheduledBooking
2024-07-23 12:16:20 +02:00
}
// Loop every second on the booking's list and move the booking that must start to a new list
// that will be looped over to start them
func (em *ExecutionManager) RetrieveNextExecutions() {
logger := oclib.GetLogger()
for {
logger.Debug().Msg("New loop")
2024-07-23 12:16:20 +02:00
em.bookings.Mu.Lock()
bookings := em.bookings.Bookings
if len(bookings) > 0 {
for i := len(bookings) - 1; i >= 0; i-- {
logger.Debug().Msg("It should start at " + bookings[i].Start.String() + " and it is now " + time.Now().UTC().String())
if bookings[i].Start.Before(time.Now().UTC()) {
logger.Info().Msg("Will execute " + bookings[i].Workflow + " soon")
2024-07-23 12:16:20 +02:00
go em.executeBooking(bookings[i])
bookings = append(bookings[:i], bookings[i+1:]...)
em.bookings.Bookings = bookings
}
}
}
2024-07-23 12:16:20 +02:00
em.bookings.Mu.Unlock()
time.Sleep(time.Second)
}
}
func (em *ExecutionManager) executeBooking(booking Booking) {
// start execution
2024-07-29 15:45:32 +02:00
// create the yaml that describes the pod : filename, path/url to Loki
2024-08-09 18:44:33 +02:00
exec_method := os.Getenv("MONITOR_METHOD")
logger := oclib.GetLogger()
if exec_method == "k8s" {
logger.Error().Msg("TODO : executing oc-monitor in a k8s")
} else {
logger.Debug().Msg("Executing oc-monitor localy")
monitor := LocalMonitor{
Logger: logger,
LokiURL: conf.GetConfig().LokiUrl, KubeURL: "localhost",
WorkflowName: booking.Workflow}
2024-08-09 18:44:33 +02:00
monitor.LaunchLocalMonitor()
2024-07-29 15:45:32 +02:00
}
}