0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-11-30 09:06:07 +01:00

Move run time reset logic to shared actions_service.ResetRunTimes function

This commit is contained in:
Ross Golder 2025-10-23 22:27:48 +07:00
parent aaf50824a7
commit ef7f7e2a5c
No known key found for this signature in database
GPG Key ID: 253A7E508D2D59CD
2 changed files with 19 additions and 16 deletions

View File

@ -126,15 +126,10 @@ func RerunWorkflowRun(ctx *context.APIContext) {
}
// Reset run's start and stop time when it is done
if run.Status.IsDone() {
run.PreviousDuration = run.Duration()
run.Started = 0
run.Stopped = 0
if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration"); err != nil {
if err := actions_service.ResetRunTimes(ctx, run); err != nil {
ctx.APIErrorInternal(err)
return
}
}
jobs, err := actions_model.GetRunJobsByRunID(ctx, run.ID)
if err != nil {
@ -425,15 +420,10 @@ func RerunWorkflowJob(ctx *context.APIContext) {
}
// Reset run's start and stop time when it is done
if run.Status.IsDone() {
run.PreviousDuration = run.Duration()
run.Started = 0
run.Stopped = 0
if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration"); err != nil {
if err := actions_service.ResetRunTimes(ctx, run); err != nil {
ctx.APIErrorInternal(err)
return
}
}
// Get all jobs that need to be rerun (including dependencies)
rerunJobs := actions_service.GetAllRerunJobs(job, allJobs)

View File

@ -4,10 +4,23 @@
package actions
import (
"context"
actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/modules/container"
)
// ResetRunTimes resets the start and stop times for a run when it is done, for rerun
func ResetRunTimes(ctx context.Context, run *actions_model.ActionRun) error {
if run.Status.IsDone() {
run.PreviousDuration = run.Duration()
run.Started = 0
run.Stopped = 0
return actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration")
}
return nil
}
// GetAllRerunJobs get all jobs that need to be rerun when job should be rerun
func GetAllRerunJobs(job *actions_model.ActionRunJob, allJobs []*actions_model.ActionRunJob) []*actions_model.ActionRunJob {
rerunJobs := []*actions_model.ActionRunJob{job}