Skip to content

Commit

Permalink
Add NotifyContext and pass it to http request
Browse files Browse the repository at this point in the history
to abort the request of the worker is killed, so worker
won't be stuck on http request

Signed-off-by: Anil Vishnoi <[email protected]>
  • Loading branch information
vishnoianil committed Apr 27, 2024
1 parent 47e4179 commit fbc98fc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions worker/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ var generateCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
logger := initLogger(Debug)
sugar := logger.Sugar()
ctx := cmd.Context()

ctx, cancel := signal.NotifyContext(cmd.Context(), syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT)
defer cancel()

sugar.Info("Starting generate worker")

Expand Down Expand Up @@ -916,7 +918,7 @@ func (w *Worker) datagenSvc(taxonomyFiles []string, outputDir string, numSamples
requestURL = strings.Replace(requestURL, "skill", "knowledge", -1)
}

request, err := http.NewRequest("POST", requestURL, bytes.NewBuffer(jsonData))
request, err := http.NewRequestWithContext(w.ctx, "POST", requestURL, bytes.NewBuffer(jsonData))
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}
Expand Down

0 comments on commit fbc98fc

Please sign in to comment.