Skip to content

Add new middleware chain methods for insertion into the middle of the list#595

Merged
mperham merged 5 commits intosidekiq:masterfrom
jackrg:master
Dec 20, 2012
Merged

Add new middleware chain methods for insertion into the middle of the list#595
mperham merged 5 commits intosidekiq:masterfrom
jackrg:master

Conversation

@jackrg
Copy link
Contributor

@jackrg jackrg commented Dec 19, 2012

Added the methods #add_before(oldklass, newklass, *args) and #add_after(oldklass, newklass, *args) to facilitate insertion immediately before and after (respectively) an existing middleware class. If the class does not exist, the insertion takes place at the top and bottom (respectively) of the chain. To insert at the top of the chain, you could write chain.add_before(nil, MyServerHook).

Mike, please note that I cannot get the tests to run on my machine. Nevertheless, I believe they should work (as does the code, which I've tested in my application).

@mperham
Copy link
Collaborator

mperham commented Dec 19, 2012

Would you make sure the API corresponds to rails' middleware API? I think it might use insert_after, etc.

@jackrg
Copy link
Contributor Author

jackrg commented Dec 19, 2012

Done.

On Dec 19, 2012, at 7:35 AM, Mike Perham notifications@github.com wrote:

Would you make sure the API corresponds to rails' middleware API? I think it might use insert_after, etc.


Reply to this email directly or view it on GitHub.

@mperham
Copy link
Collaborator

mperham commented Dec 19, 2012

Yep, looks good. http://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack

Currently your methods do nothing if the middleware already exists. Should it instead move the existing middleware?

@jackrg
Copy link
Contributor Author

jackrg commented Dec 19, 2012

Moving existing middleware would be a logical approach -- I'll work on that. Just noticed something, though, and I'm wondering if Rails middleware has the same behavior as Sidekiq: Sidekiq stops you from adding the same middleware with two different sets of arguments. I'm not sure that I can imagine why you might want to do that, but it does seem like something someone might want to do (for example, do something before before the logging middleware, then clean it up after the logging middleware. Admittedly, this is a little far-fetched and could be accomplished with two different middle wares, but just wondering …)

On Dec 19, 2012, at 8:46 AM, Mike Perham notifications@github.com wrote:

Yep, looks good. http://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack

Currently your methods do nothing if the middleware already exists. Should it instead move the existing middleware?


Reply to this email directly or view it on GitHub.

…ion rather than ignoring existing middle wares.
@jackrg
Copy link
Contributor Author

jackrg commented Dec 19, 2012

Done. My methods now move existing middleware to the requested position (delete and insert). It keeps the arguments originally associated with the middleware, so you can move a middleware without knowing it's arguments (e.g. insert_before(RetryJobs, Logging)).

On Dec 19, 2012, at 8:46 AM, Mike Perham notifications@github.com wrote:

Yep, looks good. http://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack

Currently your methods do nothing if the middleware already exists. Should it instead move the existing middleware?


Reply to this email directly or view it on GitHub.

@mperham
Copy link
Collaborator

mperham commented Dec 19, 2012

Nice work.

@mperham
Copy link
Collaborator

mperham commented Dec 19, 2012

Looks like travis failed on your test. Could you investigate?

@jackrg
Copy link
Contributor Author

jackrg commented Dec 20, 2012

Looks like I was using Array#delete when I should have been using Array#delete_if. I've corrected and pushed to my repo. Do I need to anything else?

On Dec 19, 2012, at 9:29 AM, Mike Perham notifications@github.com wrote:

Looks like travis failed on your test. Could you investigate?


Reply to this email directly or view it on GitHub.

mperham added a commit that referenced this pull request Dec 20, 2012
Add new middleware chain methods for insertion into the middle of the list
@mperham mperham merged commit 92a26bc into sidekiq:master Dec 20, 2012
@mperham
Copy link
Collaborator

mperham commented Dec 20, 2012

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants