Add queue middleware
Hoping this middleware might be useful for others, I'm submitting this PR that adds a Queue Middleware.
Basically, it creates a queue of size x and a worker pool of size y so no more than y requests can be processed at any given time while x requests can stack up in the queue.
just some quick remarks:
- It would be better if you return errors instead of using
c.Error(). It would allow middlewares up in chain to react on errors - what happens when next middleware/handler panics - will semaphores be released eventually?
Good points!
I've adjusted the code, now errors should properly return upwards the chain, and semaphores should be released through the defer mechanism. Also added a test case for panics to test that everything's working as expected.
Codecov Report
Merging #1882 (cb70c01) into master (2acb24a) will increase coverage by
0.12%. The diff coverage is87.87%.
@@ Coverage Diff @@
## master #1882 +/- ##
==========================================
+ Coverage 90.21% 90.34% +0.12%
==========================================
Files 31 32 +1
Lines 2770 2806 +36
==========================================
+ Hits 2499 2535 +36
- Misses 173 175 +2
+ Partials 98 96 -2
| Impacted Files | Coverage Δ | |
|---|---|---|
| middleware/queue.go | 87.87% <87.87%> (ø) |
|
| middleware/jwt.go | 79.80% <0.00%> (ø) |
|
| middleware/rate_limiter.go | 100.00% <0.00%> (ø) |
|
| bind.go | 89.41% <0.00%> (+0.19%) |
:arrow_up: |
| middleware/recover.go | 93.75% <0.00%> (+12.50%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 2acb24a...cb70c01. Read the comment docs.
Thanks @pafuent , I've updated the code, hope the tests go well this time 🤞
Is there anything else I should look into for this MR to get merged ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed within a month if no further activity occurs. Thank you for your contributions.
Any update on this ?