Skip to content

Commit e47fc94

Browse files
committed
NotifyWorkflowRunStatusUpdateWithReload
1 parent 84e0ee1 commit e47fc94

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

routers/web/repo/actions/view.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,7 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou
485485
}
486486

487487
actions_service.CreateCommitStatus(ctx, job)
488-
// Sync run status with db
489-
job.Run = nil
490-
if err := job.LoadAttributes(ctx); err != nil {
491-
return err
492-
}
493-
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
488+
actions_service.NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
494489
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
495490

496491
return nil
@@ -564,12 +559,7 @@ func Cancel(ctx *context_module.Context) {
564559
}
565560
if len(updatedjobs) > 0 {
566561
job := updatedjobs[0]
567-
// Sync run status with db
568-
job.Run = nil
569-
if err := job.LoadAttributes(ctx); err != nil {
570-
ctx.ServerError("LoadAttributes", err)
571-
return
572-
}
562+
actions_service.NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
573563
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
574564
}
575565
ctx.JSON(http.StatusOK, struct{}{})
@@ -615,9 +605,7 @@ func Approve(ctx *context_module.Context) {
615605

616606
if len(updatedjobs) > 0 {
617607
job := updatedjobs[0]
618-
// Sync run status with db
619-
job.Run = nil
620-
_ = job.LoadAttributes(ctx)
608+
actions_service.NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
621609
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
622610
}
623611

services/actions/clear_tasks.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,8 @@ func CancelAbandonedJobs(ctx context.Context) error {
127127
}
128128
CreateCommitStatus(ctx, job)
129129
if updated {
130-
// Sync run status with db
131-
job.Run = nil
132-
_ = job.LoadAttributes(ctx)
130+
NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
133131
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
134-
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
135132
}
136133
}
137134

services/actions/job_emitter.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
actions_model "code.gitea.io/gitea/models/actions"
1212
"code.gitea.io/gitea/models/db"
1313
"code.gitea.io/gitea/modules/graceful"
14+
"code.gitea.io/gitea/modules/log"
1415
"code.gitea.io/gitea/modules/queue"
1516
notify_service "code.gitea.io/gitea/services/notify"
1617

@@ -87,18 +88,21 @@ func checkJobsOfRun(ctx context.Context, runID int64) error {
8788
}
8889
}
8990
if runUpdated {
90-
// Sync run status with db
91-
jobs[0].Run = nil
92-
if err := jobs[0].LoadAttributes(ctx); err != nil {
93-
return err
94-
}
95-
run := jobs[0].Run
96-
notify_service.WorkflowRunStatusUpdate(ctx, run.Repo, run.TriggerUser, run)
91+
NotifyWorkflowRunStatusUpdateWithReload(ctx, jobs[0])
9792
}
9893
}
9994
return nil
10095
}
10196

97+
func NotifyWorkflowRunStatusUpdateWithReload(ctx context.Context, job *actions_model.ActionRunJob) {
98+
job.Run = nil
99+
if err := job.LoadAttributes(ctx); err != nil {
100+
log.Error("LoadAttributes: %v", err)
101+
return
102+
}
103+
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
104+
}
105+
102106
type jobStatusResolver struct {
103107
statuses map[int64]actions_model.Status
104108
needs map[int64][]int64

0 commit comments

Comments
 (0)