prep
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package daemons
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"oc-schedulerd/conf"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||
@@ -34,12 +37,21 @@ func (em *ExecutionManager) RetrieveNextExecutions() {
|
||||
continue
|
||||
}
|
||||
|
||||
lead := time.Duration(conf.GetConfig().PrepLeadSeconds) * time.Second
|
||||
for execId, exec := range orderedExec[i] {
|
||||
if i == 0 && em.isAStartingExecutionBeforeEnd(&exec) { // BEST EFFORT exception
|
||||
continue
|
||||
}
|
||||
if exec.ExecDate.Before(time.Now().UTC()) {
|
||||
logger.Info().Msg("Will execute " + execId + " soon")
|
||||
// Fire PrepLeadSeconds before the scheduled start so oc-monitord
|
||||
// has time to pre-pull images and set up infra before ExecDate.
|
||||
if exec.ExecDate.Before(time.Now().UTC().Add(lead)) {
|
||||
logger.Info().Msg(fmt.Sprintf("Launching prep for %s (scheduled %s, lead %s)",
|
||||
execId, exec.ExecDate.Format(time.RFC3339), lead))
|
||||
// Mark as STARTED immediately (before goroutine) so the next
|
||||
// SchedulePolling cycle doesn't re-pick this execution from DB.
|
||||
oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), nil).UpdateOne(map[string]interface{}{
|
||||
"state": enum.STARTED.EnumIndex(),
|
||||
}, exec.GetID())
|
||||
go em.executeExecution(&exec)
|
||||
delete(executions, execId)
|
||||
}
|
||||
@@ -78,7 +90,11 @@ func (em *ExecutionManager) executeExecution(execution *workflow_execution.Workf
|
||||
duration = int(execution.EndDate.Sub(execution.ExecDate).Seconds())
|
||||
}
|
||||
|
||||
executor = NewContainerMonitor(execution.UUID, execution.CreatorID, duration)
|
||||
if conf.GetConfig().Mode == "kubernetes" {
|
||||
executor = NewContainerMonitor(execution.UUID, execution.CreatorID, duration, execution.ExecDate)
|
||||
} else {
|
||||
executor = NewLocalMonitor(execution.UUID, execution.CreatorID, duration, execution.ExecDate)
|
||||
}
|
||||
|
||||
if executor == nil {
|
||||
logger.Fatal().Msg("Could not create executor")
|
||||
@@ -89,5 +105,5 @@ func (em *ExecutionManager) executeExecution(execution *workflow_execution.Workf
|
||||
}
|
||||
|
||||
args := executor.PrepareMonitorExec()
|
||||
executor.LaunchMonitor(args, execution.GetID(), logger)
|
||||
executor.LaunchMonitor(args, execution.GetID(), conf.GetConfig().KubeNamespace, logger)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user