diff --git a/daemons/execute_monitor_local.go b/daemons/execute_monitor_local.go index ec062dc..f87f04e 100644 --- a/daemons/execute_monitor_local.go +++ b/daemons/execute_monitor_local.go @@ -12,6 +12,7 @@ type LocalMonitor struct { LokiURL string KubeURL string WorkflowName string + Duration int Logger zerolog.Logger } @@ -29,7 +30,11 @@ func (lm *LocalMonitor) LaunchLocalMonitor() { } func (lm *LocalMonitor) execLocalKube() { - cmd := exec.Command(conf.GetConfig().MonitorPath, "-w", lm.WorkflowName, "-u", lm.LokiURL, "-m", conf.GetConfig().MongoUrl, "-d", conf.GetConfig().DBName) + args := []string{"-w", lm.WorkflowName, "-u", lm.LokiURL, "-m", conf.GetConfig().MongoUrl, "-d", conf.GetConfig().DBName} + if lm.Duration > 0 { + args = append(args, "-t", fmt.Sprintf("%d", lm.Duration)) + } + cmd := exec.Command(conf.GetConfig().MonitorPath, args...) fmt.Println("CMD", cmd) err := cmd.Start() if err != nil { diff --git a/daemons/execution_manager.go b/daemons/execution_manager.go index 80fa1af..fd1d77c 100644 --- a/daemons/execution_manager.go +++ b/daemons/execution_manager.go @@ -43,9 +43,15 @@ func (em *ExecutionManager) executeBooking(booking Booking) { logger.Error().Msg("TODO : executing oc-monitor in a k8s") } 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()) + } monitor := LocalMonitor{ Logger: logger, - LokiURL: conf.GetConfig().LokiUrl, KubeURL: "localhost", + Duration: duration, + LokiURL: conf.GetConfig().LokiUrl, + KubeURL: "localhost", WorkflowName: booking.Workflow, } monitor.LaunchLocalMonitor() diff --git a/daemons/schedule_manager.go b/daemons/schedule_manager.go index aaac939..c06be42 100644 --- a/daemons/schedule_manager.go +++ b/daemons/schedule_manager.go @@ -23,8 +23,7 @@ type Booking struct { } func (s Booking) Equals(other Booking) bool { - fmt.Println(s, other) - return s.Workflow == other.Workflow && s.Start == other.Start && s.Stop == other.Stop + return s.Workflow == other.Workflow && s.Start == other.Start } func (b *Booking) String() string { @@ -111,11 +110,9 @@ func retrieveMapFromSub(message []byte) (result_map map[string]string) { func (s *ScheduleManager) SchedulePolling() { var sleep_time float64 = 1 for { - s.getNextScheduledWorkflows(3) - - s.Logger.Info().Msg("Current list of schedules") - fmt.Println(Bookings.Bookings) + s.getNextScheduledWorkflows(1) + s.Logger.Info().Msg("Current list of schedules -------> " + fmt.Sprintf("%v", len(Bookings.Bookings))) time.Sleep(time.Minute * time.Duration(sleep_time)) } } @@ -142,8 +139,8 @@ func (s *ScheduleManager) getWorfklowExecution(from time.Time, to time.Time) (ex func (s *ScheduleManager) getNextScheduledWorkflows(minutes float64) { start := time.Now().UTC() - end := start.Add(time.Minute * time.Duration(minutes+1)).UTC() - + end := start.Add(time.Minute * time.Duration(minutes)).UTC() + start = start.Add(time.Second * time.Duration(-1)).UTC() fmt.Printf("Getting workflows execution from %s to %s \n", start.String(), end.String()) next_wf_exec, err := s.getWorfklowExecution(start, end) diff --git a/oc-schedulerd b/oc-schedulerd index 0ed07a8..11b5b43 100755 Binary files a/oc-schedulerd and b/oc-schedulerd differ