mirror of
https://github.com/hibiken/asynq.git
synced 2026-04-25 23:15:51 +03:00
[GH-ISSUE #224] [FEATURE REQUEST] Allow grouping middleware #83
Labels
No labels
CLI
bug
designing
documentation
duplicate
enhancement
good first issue
good first issue
help wanted
idea
invalid
investigate
needs-more-info
performance
pr-welcome
pull-request
question
wontfix
work in progress
work in progress
work-around-available
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/asynq#83
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @bojanz on GitHub (Jan 13, 2021).
Original GitHub issue: https://github.com/hibiken/asynq/issues/224
Originally assigned to: @hibiken on GitHub.
Is your feature request related to a problem? Please describe.
Asynq's processors resemble HTTP handlers, down to the multiplexer. This was a great choice, and makes the API easy to use.
Right now the multiplexer allows adding middleware via mux.Use(), but that middleware is always global. There is no way to declare middleware only for a certain group of tasks. If some tasks process orders and some tasks process products, it gets tricky to have a middleware that loads an order and puts it in the context, and a middleware that loads a product and puts it in the context.
Describe the solution you'd like
My suggestion is to copy the approach that routers like Chi take, and also offer a Group() method.
This would allow code like:
This is deep in the "nice to have" territory, just figured it's worth suggesting.
@hibiken commented on GitHub (Jan 13, 2021):
@bojanz Thank you for opening this issue! (Your questions and suggestions are always spot-on!)
I personally have not used
chibut this API is definitely nice to have. Especially as your Handler grows, this grouping of task handlers is going to be very helpful.Let's implement this feature. Feel free to create a PR if you are interested in implementing 👍
@bojanz commented on GitHub (Jan 13, 2021):
Thanks, I appreciate that.
I can look into this in about a week. If anyone needs it before then, feel free to go around me.
@hibiken commented on GitHub (Jan 14, 2021):
Actually I believe you can accomplish this by composing multiple
ServeMux. SinceServeMuxperforms prefix matching, as long as each "group" has the same type prefix, you can group them.Example:
Let me know if this solution works!
@bojanz commented on GitHub (Jan 19, 2021):
That works wonderfully, updated my code to do that instead of checking the task type in middleware. Thank you!
I guess all we need is a bit of docs in the wiki for this, then?
@hibiken commented on GitHub (Jan 19, 2021):
Awesome! I'll keep this issue open as a reminder to update the wiki 👍
@hibiken commented on GitHub (Apr 13, 2021):
Done! See the documentation here.