fix: update run status

This commit is contained in:
Jason Song
2022-10-21 16:15:59 +08:00
parent 3d4d44dadf
commit d6e100f6be
3 changed files with 15 additions and 1 deletions

View File

@ -84,7 +84,11 @@ func (run *Run) LoadAttributes(ctx context.Context) error {
}
func (run *Run) TakeTime() time.Duration {
return run.Started.AsTime().Sub(run.Stopped.AsTime())
started := run.Started.AsTime()
if run.Status.IsDone() {
return run.Stopped.AsTime().Sub(started)
}
return time.Since(started)
}
func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error {

View File

@ -105,12 +105,20 @@ func UpdateRunJob(ctx context.Context, job *RunJob, cols ...string) error {
return nil
}
if job.RunID == 0 {
var err error
if job, err = GetRunJobByID(ctx, job.ID); err != nil {
return err
}
}
jobs, err := GetRunJobsByRunID(ctx, job.RunID)
if err != nil {
return err
}
runStatus := aggregateJobStatus(jobs)
run := &Run{
ID: job.RunID,
Status: runStatus,