oc-schedulerd/daemons/execution_manager.go

60 lines
1.6 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-08-21 14:20:13 +02:00
workflow_execution "cloud.o-forge.io/core/oc-lib/models/workflow_execution"
2024-07-23 12:16:20 +02:00
)
2024-07-11 18:25:40 +02:00
2024-08-21 14:20:13 +02:00
var Bookings = ScheduledBooking{Bookings: map[string]*workflow_execution.WorkflowExecution{}}
2024-08-20 15:24:46 +02:00
type ExecutionManager struct{}
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-08-20 15:24:46 +02:00
Bookings.Mu.Lock()
if len(Bookings.Bookings) > 0 {
2024-08-21 14:20:13 +02:00
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)
2024-07-23 12:16:20 +02:00
}
}
}
2024-08-20 15:24:46 +02:00
Bookings.Mu.Unlock()
2024-07-23 12:16:20 +02:00
time.Sleep(time.Second)
}
}
2024-08-21 14:20:13 +02:00
func (em *ExecutionManager) executeBooking(booking *workflow_execution.WorkflowExecution) {
// 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")
2024-08-20 16:14:10 +02:00
duration := 0
2024-08-21 14:20:13 +02:00
if booking.EndDate != nil && booking.ExecDate != nil {
duration = int(booking.EndDate.Sub(*booking.ExecDate).Seconds())
2024-08-20 16:14:10 +02:00
}
monitor := LocalMonitor{
Logger: logger,
2024-08-20 16:14:10 +02:00
Duration: duration,
LokiURL: conf.GetConfig().LokiUrl,
KubeURL: "localhost",
2024-08-21 14:20:13 +02:00
ExecutionID: booking.UUID,
2024-08-20 15:24:46 +02:00
}
2024-08-09 18:44:33 +02:00
monitor.LaunchLocalMonitor()
2024-07-29 15:45:32 +02:00
}
}