minimize code + schedulerd naming + docker

This commit is contained in:
mr
2024-08-19 11:42:26 +02:00
parent c710469881
commit e5cfd6f4fb
18 changed files with 181 additions and 431 deletions

View File

@@ -1,72 +1,54 @@
package daemons
import (
"oc-scheduler/conf"
"oc-scheduler/logger"
"oc-scheduler/models"
"oc-schedulerd/conf"
"os"
"time"
oclib "cloud.o-forge.io/core/oc-lib"
)
type ExecutionManager struct {
bookings *models.ScheduledBooking
executions []models.Booking
}
func (em *ExecutionManager) SetBookings(b *models.ScheduledBooking){
em.bookings = b
bookings ScheduledBooking
}
// 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(){
if(em.bookings == nil){
logger.Logger.Error().Msg("booking has not been set in the exection manager")
return
}
for(true){
logger.Logger.Debug().Msg("New loop")
func (em *ExecutionManager) RetrieveNextExecutions() {
logger := oclib.GetLogger()
for {
logger.Debug().Msg("New loop")
em.bookings.Mu.Lock()
bookings := em.bookings.Bookings
if (len(bookings) > 0){
for i := len( bookings) - 1 ; i >= 0 ; i--{
logger.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.Logger.Info().Msg("Will execute " + bookings[i].Workflow + " soon")
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")
go em.executeBooking(bookings[i])
bookings = append(bookings[:i], bookings[i+1:]...)
em.bookings.Bookings = bookings
}
}
}
}
em.bookings.Mu.Unlock()
time.Sleep(time.Second)
}
}
func (em *ExecutionManager) executeBooking(booking models.Booking){
// start execution
func (em *ExecutionManager) executeBooking(booking Booking) {
// start execution
// create the yaml that describes the pod : filename, path/url to Loki
exec_method := os.Getenv("MONITOR_METHOD")
if exec_method == "local"{
logger.Logger.Debug().Msg("Executing oc-monitor localy")
monitor := LocalMonitor{LokiURL: conf.GetConfig().LokiUrl,KubeURL: "localhost",WorkflowName: booking.Workflow,}
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}
monitor.LaunchLocalMonitor()
}else{
logger.Logger.Error().Msg("TODO : executing oc-monitor in a k8s")
}
}