Comments (3)
For most use cases this works fine but in cases where you have a lot of middleware functions having something like:
mux.Use(someMiddlware)
or mux.Add(someMiddleware)
it would help avoid the clutter.
from asynq.
@rugwirobaker Thanks for this feature request!
Could you provide an example code for a potential API for middleware support?
Alternatively, can you simply write a middleware function and wrap your handlers with that middleware?
func loggingMiddleware(h asynq.Handler) asynq.Handler {
return asynq.HandlerFunc(func(ctx context.Context, t *asynq.Task) error {
// log something before handler processes the task
h.ProcessTask(ctx, t)
// log something after handler processed the task
})
}
mux := asynq.ServeMux()
mux.HandleFunc("something", loggingMiddleware(myHandler))
would that work? Or should the package offer better support for middleware chain?
from asynq.
Ok that makes sense.
Let's add Use
method to add middlewares to the chain, similar to gorilla/mux#Route.Use. The method should be a variadic function that takes any number of middleware functions. They should be executed in the order that they are applied.
Example:
mux := asynq.ServeMux()
mux.Use(loggingMiddleware)
mux.HandleFunc("something", myHandler)
from asynq.
Related Issues (20)
- [FEATURE REQUEST] Separate Consumer from Server HOT 3
- Question: Individual ServerInfo and identifying current server via UUID HOT 2
- [FEATURE REQUEST] Support for dragonfly HOT 1
- How to synchronize task information between asynq and database? HOT 5
- [FEATURE REQUEST] Will your add the TraceId option HOT 1
- [FEATURE REQUEST] Expose method within handler to shutdown server HOT 1
- support other redis libarary? HOT 1
- [FEATURE REQUEST] Ability to modify a task's Payload in middleware
- [FEATURE REQUEST] Task callbacks HOT 1
- [FEATURE REQUEST] Task or Queue broadcasting HOT 2
- [BUG] memory overflow issue
- [FEATURE REQUEST] Add Metadata/Headers Field for Distributed Tracing in asynq.Task HOT 2
- [FEATURE REQUEST] Multiple copies running inside the container
- [BUG] rate.NewSemaphore: type conversion failure (MakeRedisClient error?) HOT 3
- When used together with the grpc service, grpc cannot exit normally. HOT 1
- [FEATURE REQUEST] redis client version compatibility HOT 9
- [FEATURE REQUEST] Globally limit active task number according to task type HOT 1
- [FEATURE REQUEST] Can be persistent with Scheduler/Perodic job, just like we have with task HOT 1
- [BUG] Lease expiration occasionally occurs when dealing with extremely long tasks,log >>> asynq: task lease expired HOT 2
- [FEATURE REQUEST] Is it possible to provide an API to view information about ongoing tasks? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asynq.