@@ -7,9 +7,12 @@ import (
77 "github.com/diggerhq/digger/backend/models"
88 "github.com/diggerhq/digger/backend/utils"
99 orchestrator_scheduler "github.com/diggerhq/digger/libs/scheduler"
10+ "github.com/diggerhq/digger/libs/spec"
1011 "github.com/google/go-github/v61/github"
1112 "github.com/google/uuid"
1213 "log"
14+ "runtime/debug"
15+ "time"
1316)
1417
1518func DiggerJobCompleted (client * github.Client , batchId * uuid.UUID , parentJob * models.DiggerJob , repoFullName string , repoOwner string , repoName string , workflowFileName string , gh utils.GithubClientProvider ) error {
@@ -131,5 +134,50 @@ func TriggerJob(gh utils.GithubClientProvider, ciBackend ci_backends.CiBackend,
131134 return err
132135 }
133136
137+ go UpdateWorkflowUrlForJob (job , ciBackend , spec )
138+
134139 return nil
135140}
141+
142+ // This is meant to run asyncronously since it queries for job url
143+ func UpdateWorkflowUrlForJob (job * models.DiggerJob , ciBackend ci_backends.CiBackend , spec * spec.Spec ) {
144+ defer func () {
145+ if r := recover (); r != nil {
146+ log .Printf ("Recovered from panic in UpdateWorkflowUrlForJob handler: %v" , r )
147+ log .Printf ("\n === PANIC RECOVERED ===\n " )
148+ log .Printf ("Error: %v\n " , r )
149+ log .Printf ("Stack Trace:\n %s" , string (debug .Stack ()))
150+ log .Printf ("=== END PANIC ===\n " )
151+ }
152+ }()
153+
154+ batch := job .Batch
155+ // for now we only perform this update for github
156+ if batch .VCS != models .DiggerVCSGithub {
157+ return
158+ }
159+ for n := 0 ; n < 30 ; n ++ {
160+ time .Sleep (1 * time .Second )
161+ workflowUrl , err := ciBackend .GetWorkflowUrl (* spec )
162+ if err != nil {
163+ log .Printf ("DiggerJobId %v: error while attempting to fetch workflow url: %v" , job .DiggerJobID , err )
164+ } else {
165+ if workflowUrl == "#" || workflowUrl == "" {
166+ log .Printf ("DiggerJobId %v: got blank workflow url as response, ignoring" , job .DiggerJobID )
167+ } else {
168+ job .WorkflowRunUrl = & workflowUrl
169+ err = models .DB .UpdateDiggerJob (job )
170+ if err != nil {
171+ log .Printf ("DiggerJobId %v: Error updating digger job: %v" , job .DiggerJobID , err )
172+ continue
173+ } else {
174+ log .Printf ("DiggerJobId %v: successfully updated workflow run url to: %v for DiggerJobID: %v" , job .DiggerJobID , workflowUrl , job .DiggerJobID )
175+ }
176+
177+ return
178+ }
179+ }
180+ }
181+
182+ // if we get to here its highly likely that the workflow job entirely failed to start for some reason
183+ }
0 commit comments