[GH-ISSUE #866] [BUG] EnqueueContext not the original context #425

Closed
opened 2026-03-02 05:21:07 +03:00 by kerem · 2 comments
Owner

Originally created by @cexll on GitHub (Apr 18, 2024).
Original GitHub issue: https://github.com/hibiken/asynq/issues/866

Originally assigned to: @hibiken on GitHub.

Describe the bug
unable to retrieve the original context in the handler
To Reproduce


j := asynq.NewTask("product",
		payload,
		"product",
		asynq.Retention(time.Hour*24*30),
	)
                                    // ⬇️
_, err = h.asyncClient.EnqueueContext(ctx, j) // this ctx it origin ctx 
if err != nil {
    return nil, err
}

// handler 

return job.NewHandlerFunc("product", func(ctx context.Context, task *asynq.Task) error {
                   // ⬇️ 
    log.Infof("%+v", ctx) // This ctx is not the initial ctx passed in
    
    return nil
})
type Handler struct {
	Pattern string
	asynq.Handler
}

func NewHandler(pattern string, handler asynq.Handler) *Handler {
	return &Handler{Pattern: pattern, Handler: handler}
}

func NewHandlerFunc(pattern string, handler asynq.HandlerFunc) *Handler {
	return &Handler{Pattern: pattern, Handler: handler}
}

Expected behavior
get the original context

Screenshots

Environment (please complete the following information):

  • OS: MacOS 10.14 M1Pro
  • Version of asynq package v0.24.1

Additional context
Add any other context about the problem here.

Originally created by @cexll on GitHub (Apr 18, 2024). Original GitHub issue: https://github.com/hibiken/asynq/issues/866 Originally assigned to: @hibiken on GitHub. **Describe the bug** unable to retrieve the original context in the handler **To Reproduce** ```go j := asynq.NewTask("product", payload, "product", asynq.Retention(time.Hour*24*30), ) // ⬇️ _, err = h.asyncClient.EnqueueContext(ctx, j) // this ctx it origin ctx if err != nil { return nil, err } // handler return job.NewHandlerFunc("product", func(ctx context.Context, task *asynq.Task) error { // ⬇️ log.Infof("%+v", ctx) // This ctx is not the initial ctx passed in return nil }) ``` ```go type Handler struct { Pattern string asynq.Handler } func NewHandler(pattern string, handler asynq.Handler) *Handler { return &Handler{Pattern: pattern, Handler: handler} } func NewHandlerFunc(pattern string, handler asynq.HandlerFunc) *Handler { return &Handler{Pattern: pattern, Handler: handler} } ``` **Expected behavior** get the original context **Screenshots** **Environment (please complete the following information):** - OS: MacOS 10.14 M1Pro - Version of `asynq` package v0.24.1 **Additional context** Add any other context about the problem here.
kerem 2026-03-02 05:21:07 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@kamikazechaser commented on GitHub (Apr 18, 2024):

Not really a bug. That is how the library is written. EnqueueContext only overrides the context for saving the payload to Redis. The handler receives an AsynqContext which is base context (settable) + task metadata value added to it.

<!-- gh-comment-id:2062951372 --> @kamikazechaser commented on GitHub (Apr 18, 2024): Not really a bug. That is how the library is written. EnqueueContext only overrides the context for saving the payload to Redis. The handler receives an `AsynqContext` which is base context (settable) + task metadata value added to it.
Author
Owner

@cexll commented on GitHub (Apr 18, 2024):

hmm, ok Thanks
that's how it's done now

<!-- gh-comment-id:2063198641 --> @cexll commented on GitHub (Apr 18, 2024): hmm, ok Thanks that's how it's done now
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#425
No description provided.