Skip to content

Commit

Permalink
add timeout just for call’s context, not service’s ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Apr 4, 2024
1 parent 554b94e commit 5a2b2f6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backend/controller/cronjobs/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 5a2b2f6

Please sign in to comment.