[GH-ISSUE #233] [FEATURE REQUEST] Pass default queue name when initializing client #1102

Closed
opened 2026-03-07 22:05:41 +03:00 by kerem · 5 comments
Owner

Originally created by @mingrammer on GitHub (Jan 27, 2021).
Original GitHub issue: https://github.com/hibiken/asynq/issues/233

Originally assigned to: @hibiken on GitHub.

Is your feature request related to a problem? Please describe.

No, but it is for convenience. Passing the queue name when enqueue tasks every time is too cumbersome. So I'd like to suggest a feature described below.

Describe the solution you'd like

It would be good to pass the default queue name when initializing the asynq.Client like asynq.Server initialization. (If ClientOption is added, the current Option should be renamed to ServerOption I think)

client := asynq.NewClient(r, asynq.ClientOption{
    Queue: "sync-event", // If don't pass option, `default` will be used.
})
defer client.Close()

t := asynq.NewTask("sync:user", map[string]interface{}{"user_id": userID})
res, err := client.Enqueue(t) // This task will be queued in `sync-event`.

And if we pass the queue name when enqueue, the default queue name should be overridden.

// This task will be queued in `another` queue.
res, err := client.Enqueue(t1, asynq.Queue("another"))
Originally created by @mingrammer on GitHub (Jan 27, 2021). Original GitHub issue: https://github.com/hibiken/asynq/issues/233 Originally assigned to: @hibiken on GitHub. **Is your feature request related to a problem? Please describe.** No, but it is for convenience. Passing the queue name when enqueue tasks every time is too cumbersome. So I'd like to suggest a feature described below. **Describe the solution you'd like** It would be good to pass the default queue name when initializing the `asynq.Client` like `asynq.Server` initialization. (If `ClientOption` is added, the current `Option` should be renamed to `ServerOption` I think) ```go client := asynq.NewClient(r, asynq.ClientOption{ Queue: "sync-event", // If don't pass option, `default` will be used. }) defer client.Close() t := asynq.NewTask("sync:user", map[string]interface{}{"user_id": userID}) res, err := client.Enqueue(t) // This task will be queued in `sync-event`. ``` And if we pass the queue name when enqueue, the default queue name should be overridden. ```go // This task will be queued in `another` queue. res, err := client.Enqueue(t1, asynq.Queue("another")) ```
kerem 2026-03-07 22:05:41 +03:00
Author
Owner

@mingrammer commented on GitHub (Jan 27, 2021):

If you agree with it, I can work for it.

<!-- gh-comment-id:768437333 --> @mingrammer commented on GitHub (Jan 27, 2021): If you agree with it, I can work for it.
Author
Owner

@hibiken commented on GitHub (Jan 27, 2021):

@mingrammer Thank you for opening this issue!

Actually, we have SetDefaultOptions method on Client. Would this work for your use case?

Example:

client := asynq.NewClient(r)
defer client.Close()

// Set default options for "sync:user" tasks.
client.SetDefaultOptions("sync:user", asynq.Queue("sync-event"))

t := asynq.NewTask("sync:user", map[string]interface{}{"user_id": userID})
res,  err := client.Enqueue(t) // t will be enqueued to "sync-event" queue. 
<!-- gh-comment-id:768471554 --> @hibiken commented on GitHub (Jan 27, 2021): @mingrammer Thank you for opening this issue! Actually, we have [`SetDefaultOptions`](https://pkg.go.dev/github.com/hibiken/asynq#Client.SetDefaultOptions) method on `Client`. Would this work for your use case? Example: ```go client := asynq.NewClient(r) defer client.Close() // Set default options for "sync:user" tasks. client.SetDefaultOptions("sync:user", asynq.Queue("sync-event")) t := asynq.NewTask("sync:user", map[string]interface{}{"user_id": userID}) res, err := client.Enqueue(t) // t will be enqueued to "sync-event" queue. ```
Author
Owner

@mingrammer commented on GitHub (Jan 28, 2021):

@hibiken Oh, I didn't check that method. Thank you for letting me know it.

But SetDefaultOptions seems to apply to each task. How do you think about a feature that supports global default options for all tasks for a client?

<!-- gh-comment-id:768865543 --> @mingrammer commented on GitHub (Jan 28, 2021): @hibiken Oh, I didn't check that method. Thank you for letting me know it. But `SetDefaultOptions` seems to apply to each task. How do you think about a feature that supports global default options for all tasks for a client?
Author
Owner

@hibiken commented on GitHub (Jan 30, 2021):

Hmm I can see the use case for providing a method to set the global defaults. But I'm hesitant to add yet another method to set defaults.
I'll keep this issue open for now to see if other people want this feature, too.

If this feature request gets a lot of upvotes, I think it validates that this is a common need.

<!-- gh-comment-id:770164850 --> @hibiken commented on GitHub (Jan 30, 2021): Hmm I can see the use case for providing a method to set the global defaults. But I'm hesitant to add yet another method to set defaults. I'll keep this issue open for now to see if other people want this feature, too. If this feature request gets a lot of upvotes, I think it validates that this is a common need.
Author
Owner

@hibiken commented on GitHub (Feb 1, 2021):

Closing this issue for now. I'll revisit if I get similar feature requests.

<!-- gh-comment-id:770611971 --> @hibiken commented on GitHub (Feb 1, 2021): Closing this issue for now. I'll revisit if I get similar feature requests.
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#1102
No description provided.