Oclib major new version

This commit is contained in:
mr
2024-08-21 14:20:13 +02:00
parent 826650487b
commit 20b5955ba9
7 changed files with 78 additions and 99 deletions

View File

@@ -6,9 +6,10 @@ import (
"time"
oclib "cloud.o-forge.io/core/oc-lib"
workflow_execution "cloud.o-forge.io/core/oc-lib/models/workflow_execution"
)
var Bookings = ScheduledBooking{Bookings: []Booking{}}
var Bookings = ScheduledBooking{Bookings: map[string]*workflow_execution.WorkflowExecution{}}
type ExecutionManager struct{}
@@ -20,12 +21,11 @@ func (em *ExecutionManager) RetrieveNextExecutions() {
logger.Debug().Msg("New loop")
Bookings.Mu.Lock()
if len(Bookings.Bookings) > 0 {
for i := len(Bookings.Bookings) - 1; i >= 0; i-- {
logger.Debug().Msg("It should start at " + Bookings.Bookings[i].Start.String() + " and it is now " + time.Now().UTC().String())
if Bookings.Bookings[i].Start.Before(time.Now().UTC()) {
logger.Info().Msg("Will execute " + Bookings.Bookings[i].Workflow + " soon")
go em.executeBooking(Bookings.Bookings[i])
Bookings.Bookings = append(Bookings.Bookings[:i], Bookings.Bookings[i+1:]...)
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)
}
}
}
@@ -34,7 +34,7 @@ func (em *ExecutionManager) RetrieveNextExecutions() {
}
}
func (em *ExecutionManager) executeBooking(booking Booking) {
func (em *ExecutionManager) executeBooking(booking *workflow_execution.WorkflowExecution) {
// start execution
// create the yaml that describes the pod : filename, path/url to Loki
exec_method := os.Getenv("MONITOR_METHOD")
@@ -44,15 +44,15 @@ func (em *ExecutionManager) executeBooking(booking Booking) {
} else {
logger.Debug().Msg("Executing oc-monitor localy")
duration := 0
if booking.Stop != nil && booking.Start != nil {
duration = int(booking.Stop.Sub(*booking.Start).Seconds())
if booking.EndDate != nil && booking.ExecDate != nil {
duration = int(booking.EndDate.Sub(*booking.ExecDate).Seconds())
}
monitor := LocalMonitor{
Logger: logger,
Duration: duration,
LokiURL: conf.GetConfig().LokiUrl,
KubeURL: "localhost",
WorkflowName: booking.Workflow,
ExecutionID: booking.UUID,
}
monitor.LaunchLocalMonitor()
}