11package controllers
22
33import (
4+ "context"
45 "encoding/json"
56 "errors"
67 "fmt"
@@ -12,6 +13,7 @@ import (
1213 "strings"
1314 "time"
1415
16+ "github.com/diggerhq/digger/backend/logging"
1517 "github.com/diggerhq/digger/backend/middleware"
1618 "github.com/diggerhq/digger/backend/models"
1719 "github.com/diggerhq/digger/backend/services"
@@ -623,7 +625,6 @@ type SetJobStatusRequest struct {
623625 WorkflowUrl string `json:"workflow_url,omitempty"`
624626}
625627
626-
627628func (d DiggerController ) SetJobStatusForProject (c * gin.Context ) {
628629 jobId := c .Param ("jobId" )
629630 orgId , exists := c .Get (middleware .ORGANISATION_ID_KEY )
@@ -679,7 +680,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
679680 slog .Info ("Job status updated to created" , "jobId" , jobId )
680681
681682 // 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 ())
683687
684688 case "triggered" :
685689 job .Status = orchestrator_scheduler .DiggerJobTriggered
@@ -697,7 +701,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
697701 slog .Info ("Job status updated to triggered" , "jobId" , jobId )
698702
699703 // 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 ())
701708
702709 case "started" :
703710 job .Status = orchestrator_scheduler .DiggerJobStarted
@@ -719,7 +726,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
719726 slog .Info ("Job status updated to started" , "jobId" , jobId )
720727
721728 // 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 ())
723733
724734 case "succeeded" :
725735 job .Status = orchestrator_scheduler .DiggerJobSucceeded
@@ -770,7 +780,7 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
770780 "batchId" , batchId ,
771781 )
772782
773- go func () {
783+ go func (ctx context. Context ) {
774784 defer func () {
775785 if r := recover (); r != nil {
776786 stack := string (debug .Stack ())
@@ -783,8 +793,9 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
783793 )
784794 }
785795 }()
796+ defer logging .InheritRequestLogger (ctx )()
786797
787- slog .Debug ("Starting post-success job processing" , "jobId " , jobId )
798+ slog .Debug ("Starting post-success job processing" , "job_id " , jobId )
788799
789800 ghClientProvider := d .GithubClientProvider
790801 installationLink , err := models .DB .GetGithubInstallationLinkForOrg (orgId )
@@ -871,15 +882,18 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
871882 }
872883
873884 slog .Debug ("Successfully processed job completion" , "jobId" , jobId )
874- }()
885+ }(c . Request . Context () )
875886
876887 // store digger job summary
877888 if request .JobSummary != nil {
878889 models .DB .UpdateDiggerJobSummary (job .DiggerJobID , request .JobSummary .ResourcesCreated , request .JobSummary .ResourcesUpdated , request .JobSummary .ResourcesDeleted )
879890 }
880891
881892 // 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 ())
883897
884898 case "failed" :
885899 job .Status = orchestrator_scheduler .DiggerJobFailed
@@ -901,7 +915,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
901915 )
902916
903917 // 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 ())
905922
906923 default :
907924 slog .Warn ("Unexpected job status received" ,
@@ -1010,12 +1027,6 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
10101027 c .JSON (http .StatusOK , res )
10111028}
10121029
1013-
1014-
1015-
1016-
1017-
1018-
10191030func updateWorkflowUrlForJob (githubClientProvider utils.GithubClientProvider , job * models.DiggerJob ) error {
10201031 if job == nil {
10211032 return fmt .Errorf ("job is nil" )
0 commit comments