Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] EnqueueContext not the original context #866

Closed
cexll opened this issue Apr 18, 2024 · 2 comments
Closed

[BUG] EnqueueContext not the original context #866

cexll opened this issue Apr 18, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@cexll
Copy link

cexll commented Apr 18, 2024

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.

@cexll cexll added the bug Something isn't working label Apr 18, 2024
@kamikazechaser kamikazechaser added question Further information is requested and removed bug Something isn't working labels Apr 18, 2024
@kamikazechaser
Copy link
Collaborator

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.

@cexll
Copy link
Author

cexll commented Apr 18, 2024

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

@cexll cexll closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants