1
1
package controllers
2
2
3
3
import (
4
+ "context"
4
5
"encoding/json"
5
6
"errors"
6
7
"fmt"
@@ -12,6 +13,7 @@ import (
12
13
"strings"
13
14
"time"
14
15
16
+ "github.com/diggerhq/digger/backend/logging"
15
17
"github.com/diggerhq/digger/backend/middleware"
16
18
"github.com/diggerhq/digger/backend/models"
17
19
"github.com/diggerhq/digger/backend/services"
@@ -623,7 +625,6 @@ type SetJobStatusRequest struct {
623
625
WorkflowUrl string `json:"workflow_url,omitempty"`
624
626
}
625
627
626
-
627
628
func (d DiggerController ) SetJobStatusForProject (c * gin.Context ) {
628
629
jobId := c .Param ("jobId" )
629
630
orgId , exists := c .Get (middleware .ORGANISATION_ID_KEY )
@@ -679,7 +680,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
679
680
slog .Info ("Job status updated to created" , "jobId" , jobId )
680
681
681
682
// Update PR comment with real-time status
682
- go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "created" )
683
+ go func (ctx context.Context ) {
684
+ defer logging .InheritRequestLogger (ctx )()
685
+ utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "created" )
686
+ }(c .Request .Context ())
683
687
684
688
case "triggered" :
685
689
job .Status = orchestrator_scheduler .DiggerJobTriggered
@@ -697,7 +701,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
697
701
slog .Info ("Job status updated to triggered" , "jobId" , jobId )
698
702
699
703
// Update PR comment with real-time status
700
- go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "triggered" )
704
+ go func (ctx context.Context ) {
705
+ defer logging .InheritRequestLogger (ctx )()
706
+ utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "triggered" )
707
+ }(c .Request .Context ())
701
708
702
709
case "started" :
703
710
job .Status = orchestrator_scheduler .DiggerJobStarted
@@ -719,7 +726,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
719
726
slog .Info ("Job status updated to started" , "jobId" , jobId )
720
727
721
728
// Update PR comment with real-time status
722
- go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "started" )
729
+ go func (ctx context.Context ) {
730
+ defer logging .InheritRequestLogger (ctx )()
731
+ utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "started" )
732
+ }(c .Request .Context ())
723
733
724
734
case "succeeded" :
725
735
job .Status = orchestrator_scheduler .DiggerJobSucceeded
@@ -770,7 +780,7 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
770
780
"batchId" , batchId ,
771
781
)
772
782
773
- go func () {
783
+ go func (ctx context. Context ) {
774
784
defer func () {
775
785
if r := recover (); r != nil {
776
786
stack := string (debug .Stack ())
@@ -783,8 +793,9 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
783
793
)
784
794
}
785
795
}()
796
+ defer logging .InheritRequestLogger (ctx )()
786
797
787
- slog .Debug ("Starting post-success job processing" , "jobId " , jobId )
798
+ slog .Debug ("Starting post-success job processing" , "job_id " , jobId )
788
799
789
800
ghClientProvider := d .GithubClientProvider
790
801
installationLink , err := models .DB .GetGithubInstallationLinkForOrg (orgId )
@@ -871,15 +882,18 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
871
882
}
872
883
873
884
slog .Debug ("Successfully processed job completion" , "jobId" , jobId )
874
- }()
885
+ }(c . Request . Context () )
875
886
876
887
// store digger job summary
877
888
if request .JobSummary != nil {
878
889
models .DB .UpdateDiggerJobSummary (job .DiggerJobID , request .JobSummary .ResourcesCreated , request .JobSummary .ResourcesUpdated , request .JobSummary .ResourcesDeleted )
879
890
}
880
891
881
892
// Update PR comment with real-time status for succeeded job
882
- go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "succeeded" )
893
+ go func (ctx context.Context ) {
894
+ defer logging .InheritRequestLogger (ctx )()
895
+ utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "succeeded" )
896
+ }(c .Request .Context ())
883
897
884
898
case "failed" :
885
899
job .Status = orchestrator_scheduler .DiggerJobFailed
@@ -901,7 +915,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
901
915
)
902
916
903
917
// Update PR comment with real-time status for failed job
904
- go utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "failed" )
918
+ go func (ctx context.Context ) {
919
+ defer logging .InheritRequestLogger (ctx )()
920
+ utils .UpdatePRComment (d .GithubClientProvider , jobId , job , "failed" )
921
+ }(c .Request .Context ())
905
922
906
923
default :
907
924
slog .Warn ("Unexpected job status received" ,
@@ -1010,12 +1027,6 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
1010
1027
c .JSON (http .StatusOK , res )
1011
1028
}
1012
1029
1013
-
1014
-
1015
-
1016
-
1017
-
1018
-
1019
1030
func updateWorkflowUrlForJob (githubClientProvider utils.GithubClientProvider , job * models.DiggerJob ) error {
1020
1031
if job == nil {
1021
1032
return fmt .Errorf ("job is nil" )
0 commit comments