@@ -38,13 +38,17 @@ type DefaultWorkerContext struct {
3838//
3939//nolint:gocritic // ptrToRefParam: API compatibility requirement - changing pointer to value would be breaking change
4040func (wc * DefaultWorkerContext ) FinishJob (result string , outputs * map [string ]protocol.VariableValue ) {
41- if strings .EqualFold (wc .Message ().MessageType , "RunnerJobRequest" ) {
41+ jobreq := wc .Message ()
42+ if jobreq == nil {
43+ return
44+ }
45+ if strings .EqualFold (jobreq .MessageType , "RunnerJobRequest" ) {
4246 payload := & run.CompleteJobRequest {
43- PlanID : wc . Message () .Plan .PlanID ,
44- JobID : wc . Message () .JobID ,
47+ PlanID : jobreq .Plan .PlanID ,
48+ JobID : jobreq .JobID ,
4549 Conclusion : strings .ToLower (result ),
4650 Outputs : nil ,
47- BillingOwnerID : wc . Message () .BillingOwnerID ,
51+ BillingOwnerID : jobreq .BillingOwnerID ,
4852 }
4953 if outputs != nil {
5054 payload .Outputs = * outputs
@@ -70,38 +74,42 @@ func (wc *DefaultWorkerContext) FinishJob(result string, outputs *map[string]pro
7074 completejobURL .Path = path .Join (completejobURL .Path , "completejob" )
7175 for i := 0 ; ; i ++ {
7276 if err := wc .VssConnection .RequestWithContext2 (context .Background (), "POST" , completejobURL .String (), "" , payload , nil ); err != nil {
73- wc .RunnerLogger .Printf ("Failed to finish Job '%v' with Status %v: %v\n " , wc . Message () .JobDisplayName , result , err .Error ())
77+ wc .RunnerLogger .Printf ("Failed to finish Job '%v' with Status %v: %v\n " , jobreq .JobDisplayName , result , err .Error ())
7478 } else {
75- wc .RunnerLogger .Printf ("Finished Job '%v' with Status %v\n " , wc . Message () .JobDisplayName , result )
79+ wc .RunnerLogger .Printf ("Finished Job '%v' with Status %v\n " , jobreq .JobDisplayName , result )
7680 break
7781 }
7882 if i < workerMaxRetryAttempts {
7983 wc .RunnerLogger .Printf ("Retry finishing '%v' in %d seconds attempt %v of %d\n " ,
80- wc . Message () .JobDisplayName , workerRetry / time .Second , i + 1 , workerMaxRetryAttempts )
84+ jobreq .JobDisplayName , workerRetry / time .Second , i + 1 , workerMaxRetryAttempts )
8185 <- time .After (workerRetry )
8286 } else {
8387 break
8488 }
8589 }
8690 return
8791 }
92+ if jobreq .Plan == nil {
93+ wc .RunnerLogger .Printf ("Invalid Job %s\n " , jobreq .JobID )
94+ return
95+ }
8896 finish := & protocol.JobEvent {
8997 Name : "JobCompleted" ,
90- JobID : wc . Message () .JobID ,
91- RequestID : wc . Message () .RequestID ,
98+ JobID : jobreq .JobID ,
99+ RequestID : jobreq .RequestID ,
92100 Result : result ,
93101 Outputs : outputs ,
94102 }
95103 for i := 0 ; ; i ++ {
96- if err := wc .VssConnection .FinishJob (finish , wc . Message () .Plan ); err != nil {
97- wc .RunnerLogger .Printf ("Failed to finish Job '%v' with Status %v: %v\n " , wc . Message () .JobDisplayName , result , err .Error ())
104+ if err := wc .VssConnection .FinishJob (finish , jobreq .Plan ); err != nil {
105+ wc .RunnerLogger .Printf ("Failed to finish Job '%v' with Status %v: %v\n " , jobreq .JobDisplayName , result , err .Error ())
98106 } else {
99- wc .RunnerLogger .Printf ("Finished Job '%v' with Status %v\n " , wc . Message () .JobDisplayName , result )
107+ wc .RunnerLogger .Printf ("Finished Job '%v' with Status %v\n " , jobreq .JobDisplayName , result )
100108 break
101109 }
102110 if i < workerMaxRetryAttempts {
103111 wc .RunnerLogger .Printf ("Retry finishing '%v' in %d seconds attempt %v of %d\n " ,
104- wc . Message () .JobDisplayName , workerRetry / time .Second , i + 1 , workerMaxRetryAttempts )
112+ jobreq .JobDisplayName , workerRetry / time .Second , i + 1 , workerMaxRetryAttempts )
105113 <- time .After (workerRetry )
106114 } else {
107115 break
@@ -110,10 +118,14 @@ func (wc *DefaultWorkerContext) FinishJob(result string, outputs *map[string]pro
110118}
111119
112120func (wc * DefaultWorkerContext ) FailInitJob (title , message string ) {
121+ jobreq := wc .Message ()
122+ if jobreq == nil {
123+ return
124+ }
113125 if wc .Logger ().Current () != nil {
114126 wc .Logger ().Current ().Complete ("Failed" )
115127 }
116- timelineEntry := protocol .CreateTimelineEntry (wc . Message () .JobID , "__fatal" , title )
128+ timelineEntry := protocol .CreateTimelineEntry (jobreq .JobID , "__fatal" , title )
117129 e := wc .Logger ().Append (& timelineEntry )
118130 e .Start ()
119131 if wc .Logger ().Current () != e {
@@ -147,7 +159,11 @@ func (wc *DefaultWorkerContext) JobExecCtx() context.Context {
147159}
148160
149161func (wc * DefaultWorkerContext ) Init () {
150- jobVssConnection , vssConnectionData , err := wc .Message ().GetConnection ("SystemVssConnection" )
162+ jobreq := wc .Message ()
163+ if jobreq == nil {
164+ return
165+ }
166+ jobVssConnection , vssConnectionData , err := jobreq .GetConnection ("SystemVssConnection" )
151167 if err != nil {
152168 wc .RunnerLogger .Printf ("Failed to find the SystemVssConnection Endpoint, try to finish job as failed" )
153169 wc .FinishJob ("Failed" , & map [string ]protocol.VariableValue {})
@@ -159,7 +175,6 @@ func (wc *DefaultWorkerContext) Init() {
159175 }
160176 wc .VssConnection = jobVssConnection
161177
162- jobreq := wc .Message ()
163178 resultsEndpoint , hasResultsEndpoint := jobreq .Variables ["system.github.results_endpoint" ]
164179 wc .JobLogger = & logger.JobLogger {
165180 JobRequest : jobreq ,
@@ -194,9 +209,9 @@ func (wc *DefaultWorkerContext) Init() {
194209 },
195210 }
196211 }
197- timelineEntry := protocol .CreateTimelineEntry ("" , wc . Message (). JobName , wc . Message () .JobDisplayName )
212+ timelineEntry := protocol .CreateTimelineEntry ("" , jobreq . JobName , jobreq .JobDisplayName )
198213 jobEntry := wc .Logger ().Append (& timelineEntry )
199- jobEntry .ID = wc . Message () .JobID
214+ jobEntry .ID = jobreq .JobID
200215 jobEntry .Type = "Job"
201216 jobEntry .Order = 0
202217 jobEntry .Start ()
0 commit comments