echo icon indicating copy to clipboard operation
echo copied to clipboard

Add queue middleware

Open adrianlungu opened this issue 4 years ago • 7 comments

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.

adrianlungu avatar May 24 '21 09:05 adrianlungu

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?

aldas avatar May 24 '21 10:05 aldas

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.

adrianlungu avatar May 24 '21 12:05 adrianlungu

Codecov Report

Merging #1882 (cb70c01) into master (2acb24a) will increase coverage by 0.12%. The diff coverage is 87.87%.

Impacted file tree graph

@@            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 data Powered by Codecov. Last update 2acb24a...cb70c01. Read the comment docs.

codecov[bot] avatar May 27 '21 05:05 codecov[bot]

Thanks @pafuent , I've updated the code, hope the tests go well this time 🤞

adrianlungu avatar Jun 08 '21 10:06 adrianlungu

Is there anything else I should look into for this MR to get merged ?

adrianlungu avatar Aug 23 '21 05:08 adrianlungu

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.

stale[bot] avatar Jan 09 '22 00:01 stale[bot]

Any update on this ?

adrianlungu avatar Jan 14 '22 15:01 adrianlungu