2024-07-11 18:25:40 +02:00
|
|
|
package daemons
|
|
|
|
|
2024-07-23 12:16:20 +02:00
|
|
|
import (
|
2025-02-05 08:38:50 +01:00
|
|
|
"fmt"
|
2024-07-29 15:45:32 +02:00
|
|
|
"os"
|
2024-07-23 12:16:20 +02:00
|
|
|
"time"
|
2024-08-19 11:42:26 +02:00
|
|
|
|
|
|
|
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
|
2024-08-19 11:42:26 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2024-08-19 11:42:26 +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) {
|
2024-08-19 11:42:26 +02:00
|
|
|
// 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")
|
2024-08-19 11:42:26 +02:00
|
|
|
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
|
2025-02-14 11:59:32 +01:00
|
|
|
if Execution.EndDate != nil {
|
|
|
|
duration = int(Execution.EndDate.Sub(Execution.ExecDate).Seconds())
|
2024-08-20 16:14:10 +02:00
|
|
|
}
|
2024-08-19 11:42:26 +02:00
|
|
|
monitor := LocalMonitor{
|
2025-01-17 17:21:17 +01:00
|
|
|
Logger: logger,
|
|
|
|
Duration: duration,
|
2025-04-17 19:58:59 +02:00
|
|
|
ExecutionID: Execution.ExecutionsID,
|
2025-02-14 11:59:32 +01:00
|
|
|
PeerID: Execution.CreatorID,
|
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
|
|
|
}
|
|
|
|
}
|