oc-schedulerd/daemons/execution_manager.go

82 lines
2.4 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 (
"fmt"
"oc-schedulerd/conf"
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
2025-02-14 11:59:32 +01:00
var Executions = ScheduledExecution{Execs: []*workflow_execution.WorkflowExecution{}}
2024-08-20 15:24:46 +02:00
type ExecutionManager struct{}
2024-07-23 12:16:20 +02:00
2025-02-14 11:59:32 +01:00
// Loop every second on the Execution's list and move the Execution that must start to a new list
2024-07-23 12:16:20 +02:00
// that will be looped over to start them
func (em *ExecutionManager) RetrieveNextExecutions() {
logger := oclib.GetLogger()
for {
2025-02-14 11:59:32 +01:00
fmt.Println("Checking for executions", len(Executions.Execs))
Executions.Mu.Lock()
if len(Executions.Execs) > 0 {
executions := Executions.Execs
for i := len(executions) - 1; i >= 0; i-- {
if executions[i].ExecDate.Before(time.Now().UTC()) {
logger.Info().Msg("Will execute " + executions[i].UUID + " soon")
go em.executeExecution(executions[i])
Executions.Execs = append(executions[:i], executions[i+1:]...)
2024-07-23 12:16:20 +02:00
}
}
}
2025-02-14 11:59:32 +01:00
Executions.Mu.Unlock()
2024-07-23 12:16:20 +02:00
time.Sleep(time.Second)
}
}
2025-02-14 11:59:32 +01:00
func (em *ExecutionManager) executeExecution(Execution *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
var executor Executor
// exec_method := os.Getenv("MONITOR_METHOD")
logger := oclib.GetLogger()
duration := 0
if Execution.EndDate != nil {
duration = int(Execution.EndDate.Sub(Execution.ExecDate).Seconds())
2024-07-29 15:45:32 +02:00
}
if conf.GetConfig().Mode == "local" {
executor = NewLocalMonitor(Execution.ExecutionsID, Execution.CreatorID, duration)
}
if conf.GetConfig().Mode == "container" {
executor = NewContainerMonitor(Execution.ExecutionsID, Execution.CreatorID, duration)
}
if executor == nil {
logger.Fatal().Msg("Could not create logger")
}
args := executor.PrepareMonitorExec()
executor.LaunchMonitor(args,logger)
// if exec_method == "k8s" {
// logger.Error().Msg("TODO : executing oc-monitor in a k8s")
// } else {
// logger.Debug().Msg("Executing oc-monitor localy")
// duration := 0
// if Execution.EndDate != nil {
// duration = int(Execution.EndDate.Sub(Execution.ExecDate).Seconds())
// }
// monitor := LocalMonitor{
// Logger: logger,
// Duration: duration,
// ExecutionID: Execution.ExecutionsID,
// PeerID: Execution.CreatorID,
// LokiUrl: conf.GetConfig().LokiUrl,
// }
// monitor.LaunchLocalMonitor()
// }
2024-07-29 15:45:32 +02:00
}