Skip to content

Commit bf93ee1

Browse files
Fix handle renewJob error return values and log them (#216)
1 parent 9c140ac commit bf93ee1

1 file changed

Lines changed: 31 additions & 21 deletions

File tree

actionsrunner/runner.go

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -528,27 +528,7 @@ func runJob(runnerenv RunnerEnvironment, joblock *sync.Mutex, vssConnection *pro
528528
con := *vssConnection
529529
go func() {
530530
for {
531-
var renewErr error
532-
if runServiceURL != "" {
533-
jobVssConnection, _, _ := jobreq.GetConnection("SystemVssConnection")
534-
jobVssConnection.Trace = con.Trace
535-
renewjobURL, _ := url.Parse(runServiceURL)
536-
renewjobURL.Path = path.Join(renewjobURL.Path, "renewjob")
537-
jobVssConnection.TenantURL = runServiceURL
538-
payload := &runservice.RenewJobRequest{
539-
PlanID: jobreq.Plan.PlanID,
540-
JobID: jobreq.JobID,
541-
}
542-
resp := &runservice.RenewJobResponse{}
543-
renewErr = jobVssConnection.RequestWithContext2(jobctx, "POST", renewjobURL.String(), "", payload, &resp)
544-
} else {
545-
renewErr = con.RequestWithContext(jobctx, "fc825784-c92a-4299-9221-998a02d1b54f", "5.1-preview", "PATCH", map[string]string{
546-
"poolId": fmt.Sprint(instance.PoolID),
547-
"requestId": fmt.Sprint(jobreq.RequestID),
548-
}, map[string]string{
549-
"lockToken": "00000000-0000-0000-0000-000000000000",
550-
}, &protocol.RenewAgent{RequestID: jobreq.RequestID}, nil)
551-
}
531+
renewErr := renewJob(jobctx, runServiceURL, jobreq, &con, instance)
552532
if renewErr != nil {
553533
if errors.Is(renewErr, context.Canceled) {
554534
return
@@ -634,3 +614,33 @@ func runJob(runnerenv RunnerEnvironment, joblock *sync.Mutex, vssConnection *pro
634614
}
635615
}()
636616
}
617+
618+
func renewJob(jobctx context.Context, runServiceURL string, jobreq *protocol.AgentJobRequestMessage,
619+
con *protocol.VssConnection, instance *runnerconfiguration.RunnerInstance,
620+
) error {
621+
if runServiceURL != "" {
622+
jobVssConnection, _, conErr := jobreq.GetConnection("SystemVssConnection")
623+
if conErr != nil {
624+
return conErr
625+
}
626+
jobVssConnection.Trace = con.Trace
627+
renewjobURL, urlErr := url.Parse(runServiceURL)
628+
if urlErr != nil {
629+
return urlErr
630+
}
631+
renewjobURL.Path = path.Join(renewjobURL.Path, "renewjob")
632+
jobVssConnection.TenantURL = runServiceURL
633+
payload := &runservice.RenewJobRequest{
634+
PlanID: jobreq.Plan.PlanID,
635+
JobID: jobreq.JobID,
636+
}
637+
resp := &runservice.RenewJobResponse{}
638+
return jobVssConnection.RequestWithContext2(jobctx, "POST", renewjobURL.String(), "", payload, &resp)
639+
}
640+
return con.RequestWithContext(jobctx, "fc825784-c92a-4299-9221-998a02d1b54f", "5.1-preview", "PATCH", map[string]string{
641+
"poolId": fmt.Sprint(instance.PoolID),
642+
"requestId": fmt.Sprint(jobreq.RequestID),
643+
}, map[string]string{
644+
"lockToken": "00000000-0000-0000-0000-000000000000",
645+
}, &protocol.RenewAgent{RequestID: jobreq.RequestID}, nil)
646+
}

0 commit comments

Comments
 (0)