runservice: refactor fetch phase check

Use dedicated functions
This commit is contained in:
Simone Gotti 2019-03-29 09:00:19 +01:00
parent 7fa14c1b7a
commit 1657a35a6f
2 changed files with 20 additions and 17 deletions

View File

@ -1030,27 +1030,17 @@ func (s *Scheduler) finishedRunArchiver(ctx context.Context, r *types.Run) error
done := true done := true
for _, rt := range r.RunTasks { for _, rt := range r.RunTasks {
// check all logs are fetched // check that all logs are fetched
if rt.SetupStep.LogPhase != types.RunTaskFetchPhaseFinished { if !rt.LogsFetchFinished() {
done = false done = false
break break
} }
for _, rts := range rt.Steps { // check that all archives are fetched
lp := rts.LogPhase if !rt.ArchivesFetchFinished() {
if lp != types.RunTaskFetchPhaseFinished {
done = false done = false
break break
} }
} }
// check all archives are fetched
for _, lp := range rt.WorkspaceArchivesPhase {
if lp != types.RunTaskFetchPhaseFinished {
done = false
break
}
}
}
if !done { if !done {
return nil return nil
} }

View File

@ -184,9 +184,22 @@ type RunTask struct {
EndTime *time.Time `json:"end_time,omitempty"` 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 { func (rt *RunTask) ArchivesFetchFinished() bool {
for _, p := range rt.WorkspaceArchivesPhase { for _, p := range rt.WorkspaceArchivesPhase {
if p == RunTaskFetchPhaseNotStarted { if p != RunTaskFetchPhaseFinished {
return false return false
} }
} }