From 1657a35a6fb699614822c717da3e681e9787e6c0 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Fri, 29 Mar 2019 09:00:19 +0100 Subject: [PATCH] runservice: refactor fetch phase check Use dedicated functions --- .../runservice/scheduler/scheduler.go | 22 +++++-------------- internal/services/runservice/types/types.go | 15 ++++++++++++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/internal/services/runservice/scheduler/scheduler.go b/internal/services/runservice/scheduler/scheduler.go index ec145f8..0d4acf3 100644 --- a/internal/services/runservice/scheduler/scheduler.go +++ b/internal/services/runservice/scheduler/scheduler.go @@ -1030,25 +1030,15 @@ func (s *Scheduler) finishedRunArchiver(ctx context.Context, r *types.Run) error done := true for _, rt := range r.RunTasks { - // check all logs are fetched - if rt.SetupStep.LogPhase != types.RunTaskFetchPhaseFinished { + // check that all logs are fetched + if !rt.LogsFetchFinished() { done = false break } - for _, rts := range rt.Steps { - lp := rts.LogPhase - if lp != types.RunTaskFetchPhaseFinished { - done = false - break - } - } - - // check all archives are fetched - for _, lp := range rt.WorkspaceArchivesPhase { - if lp != types.RunTaskFetchPhaseFinished { - done = false - break - } + // check that all archives are fetched + if !rt.ArchivesFetchFinished() { + done = false + break } } if !done { diff --git a/internal/services/runservice/types/types.go b/internal/services/runservice/types/types.go index 71e5ca0..a84884d 100644 --- a/internal/services/runservice/types/types.go +++ b/internal/services/runservice/types/types.go @@ -184,9 +184,22 @@ type RunTask struct { EndTime *time.Time `json:"end_time,omitempty"` } +func (rt *RunTask) LogsFetchFinished() bool { + if rt.SetupStep.LogPhase != RunTaskFetchPhaseFinished { + return false + } + for _, rts := range rt.Steps { + lp := rts.LogPhase + if lp != RunTaskFetchPhaseFinished { + return false + } + } + return true +} + func (rt *RunTask) ArchivesFetchFinished() bool { for _, p := range rt.WorkspaceArchivesPhase { - if p == RunTaskFetchPhaseNotStarted { + if p != RunTaskFetchPhaseFinished { return false } }