From 5a2b2f6ea505e5622b50fdecb94e46321a5bbb3c Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Fri, 5 Apr 2024 09:08:12 +1100 Subject: [PATCH] =?UTF-8?q?add=20timeout=20just=20for=20call=E2=80=99s=20c?= =?UTF-8?q?ontext,=20not=20service=E2=80=99s=20ctx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/controller/cronjobs/cronjobs.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/controller/cronjobs/cronjobs.go b/backend/controller/cronjobs/cronjobs.go index 732654368e..230b418247 100644 --- a/backend/controller/cronjobs/cronjobs.go +++ b/backend/controller/cronjobs/cronjobs.go @@ -153,9 +153,6 @@ func (s *Service) resetJobs(ctx context.Context) (time.Duration, error) { } func (s *Service) executeJob(ctx context.Context, job dal.CronJob) { - ctx, cancel := context.WithTimeout(ctx, s.config.Timeout) - defer cancel() - logger := log.FromContext(ctx) requestBody := map[string]any{} requestJSON, err := json.Marshal(requestBody) @@ -168,7 +165,10 @@ func (s *Service) executeJob(ctx context.Context, job dal.CronJob) { Verb: &schemapb.Ref{Module: job.Module, Name: job.Verb}, Body: requestJSON, }) - _, err = s.executor.Call(ctx, req) + + callCtx, cancel := context.WithTimeout(ctx, s.config.Timeout) + defer cancel() + _, err = s.executor.Call(callCtx, req) if err != nil { logger.Errorf(err, "failed to execute cron job %v:%v", job.DeploymentKey, job.Verb) }