Skip to content

Commit ef7f7e2

Browse files
committed
Move run time reset logic to shared actions_service.ResetRunTimes function
1 parent aaf5082 commit ef7f7e2

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

routers/api/v1/repo/actions_run.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,9 @@ func RerunWorkflowRun(ctx *context.APIContext) {
126126
}
127127

128128
// Reset run's start and stop time when it is done
129-
if run.Status.IsDone() {
130-
run.PreviousDuration = run.Duration()
131-
run.Started = 0
132-
run.Stopped = 0
133-
if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration"); err != nil {
134-
ctx.APIErrorInternal(err)
135-
return
136-
}
129+
if err := actions_service.ResetRunTimes(ctx, run); err != nil {
130+
ctx.APIErrorInternal(err)
131+
return
137132
}
138133

139134
jobs, err := actions_model.GetRunJobsByRunID(ctx, run.ID)
@@ -425,14 +420,9 @@ func RerunWorkflowJob(ctx *context.APIContext) {
425420
}
426421

427422
// Reset run's start and stop time when it is done
428-
if run.Status.IsDone() {
429-
run.PreviousDuration = run.Duration()
430-
run.Started = 0
431-
run.Stopped = 0
432-
if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration"); err != nil {
433-
ctx.APIErrorInternal(err)
434-
return
435-
}
423+
if err := actions_service.ResetRunTimes(ctx, run); err != nil {
424+
ctx.APIErrorInternal(err)
425+
return
436426
}
437427

438428
// Get all jobs that need to be rerun (including dependencies)

services/actions/rerun.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@
44
package actions
55

66
import (
7+
"context"
8+
79
actions_model "code.gitea.io/gitea/models/actions"
810
"code.gitea.io/gitea/modules/container"
911
)
1012

13+
// ResetRunTimes resets the start and stop times for a run when it is done, for rerun
14+
func ResetRunTimes(ctx context.Context, run *actions_model.ActionRun) error {
15+
if run.Status.IsDone() {
16+
run.PreviousDuration = run.Duration()
17+
run.Started = 0
18+
run.Stopped = 0
19+
return actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration")
20+
}
21+
return nil
22+
}
23+
1124
// GetAllRerunJobs get all jobs that need to be rerun when job should be rerun
1225
func GetAllRerunJobs(job *actions_model.ActionRunJob, allJobs []*actions_model.ActionRunJob) []*actions_model.ActionRunJob {
1326
rerunJobs := []*actions_model.ActionRunJob{job}

0 commit comments

Comments
 (0)