Skip to content

Commit d404c60

Browse files
committed
Sync run status with db prior webhook delivery
* fixes status glitch of webhook * e.g. queued for cancel * e.g. completed for rerun
1 parent cdefda1 commit d404c60

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

routers/web/repo/actions/view.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou
459459
}
460460

461461
actions_service.CreateCommitStatus(ctx, job)
462+
// Sync run status with db
463+
job.Run = nil
462464
_ = job.LoadAttributes(ctx)
463465
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
464466
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
@@ -564,6 +566,9 @@ func Cancel(ctx *context_module.Context) {
564566
}
565567
if len(updatedjobs) > 0 {
566568
job := updatedjobs[0]
569+
// Sync run status with db
570+
job.Run = nil
571+
job.LoadAttributes(ctx)
567572
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
568573
}
569574
ctx.JSON(http.StatusOK, struct{}{})
@@ -607,15 +612,19 @@ func Approve(ctx *context_module.Context) {
607612

608613
actions_service.CreateCommitStatus(ctx, jobs...)
609614

610-
for _, job := range updatedjobs {
611-
_ = job.LoadAttributes(ctx)
612-
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
613-
}
614615
if len(updatedjobs) > 0 {
615616
job := updatedjobs[0]
617+
// Sync run status with db
618+
job.Run = nil
619+
job.LoadAttributes(ctx)
616620
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
617621
}
618622

623+
for _, job := range updatedjobs {
624+
_ = job.LoadAttributes(ctx)
625+
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
626+
}
627+
619628
ctx.JSON(http.StatusOK, struct{}{})
620629
}
621630

services/actions/clear_tasks.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ func CancelAbandonedJobs(ctx context.Context) error {
127127
}
128128
CreateCommitStatus(ctx, job)
129129
if updated {
130+
// Sync run status with db
131+
job.Run = nil
130132
_ = job.LoadAttributes(ctx)
131133
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
132-
if job.Run != nil {
133-
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
134-
}
134+
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
135135
}
136136
}
137137

services/actions/job_emitter.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,17 @@ func checkJobsOfRun(ctx context.Context, runID int64) error {
8080
}
8181
if len(jobs) > 0 {
8282
runUpdated := true
83-
run := jobs[0].Run
8483
for _, job := range jobs {
8584
if !job.Status.IsDone() {
8685
runUpdated = false
8786
break
8887
}
8988
}
9089
if runUpdated {
90+
// Sync run status with db
91+
jobs[0].Run = nil
92+
jobs[0].LoadAttributes(ctx)
93+
run := jobs[0].Run
9194
notify_service.WorkflowRunStatusUpdate(ctx, run.Repo, run.TriggerUser, run)
9295
}
9396
}

0 commit comments

Comments
 (0)