Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor sidekiq handler #197

Merged
merged 7 commits into from
Feb 5, 2015
Merged

Conversation

jjb
Copy link
Contributor

@jjb jjb commented Jan 8, 2015

  • DRYed up the code by moving the error handling code into its own method that can be reused
  • DRYed up the code by removing redundant invocations of Sidekiq.configure_server do |config|
  • moved PARAM_BLACKLIST out of the global namespace

(the first one is what inspired me to do the refactoring in the first place, because in my project i need to change the behavior and currently have to do a monkeypatch which replicates all the code. after this refactoring, i can use alias_method_chain)

let me know what you think!

/cc @dadadadave

@brianr
Copy link
Member

brianr commented Jan 8, 2015

Nice, thanks @jjb!

@jondeandres can you review this?

config.server_middleware do |chain|
chain.add Rollbar::Sidekiq
chain.add Rollbar::SidekiqErrorHandlingMiddleware
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are expecting here to use Rollbar::SidekiqErrorHandler, which is the module name you've defined above.

@jjb
Copy link
Contributor Author

jjb commented Jan 8, 2015

@jondeandres 🤦 thanks for pointing out those obvious errors -- I was tired last night when I threw that together.

I've now fixed everything and also split it up into multiple commits.

There are no tests for this, perhaps we can write some before merging.

@jjb
Copy link
Contributor Author

jjb commented Jan 8, 2015

Are there tests for something else that I can look at to base tests for this off of?

@jondeandres
Copy link
Contributor

@jjb cool 👍

you can write a test for this using the inline option in sidekiq, https://github.com/mperham/sidekiq/wiki/Testing. Just write a job that will crash, enqueue it, and check that the report was sent. Rollbar.last_report should return something after the report is sent.

I'll be on freenode as 'jandres' if you want to chat it.

@jjb
Copy link
Contributor Author

jjb commented Jan 9, 2015

@jondeandres thanks

seems like the block given to Sidekiq.configure_server does not get executed in the testing environment

i'm exploring why that might be... let me know if you have an idea

@jjb
Copy link
Contributor Author

jjb commented Jan 9, 2015

@jondeandres okay I figured out it's because of my sidekiq test environment -- I submitted this ticket, we'll see what @mperham says sidekiq/sidekiq#2128

@jondeandres
Copy link
Contributor

it could because this?

https://github.com/mperham/sidekiq/blob/master/lib/sidekiq.rb#L53
https://github.com/mperham/sidekiq/blob/master/lib/sidekiq.rb#L67

require 'sidekiq/cli' and it should work.

But now I'm thinking that perhaps middlewares will not be executed in tests environments? I've never tested Sidekiq jobs, but probably Sidekiq will have this documented.

@jjb
Copy link
Contributor Author

jjb commented Feb 2, 2015

@jondeandres finally got around to finishing this up, take a look

@jjb
Copy link
Contributor Author

jjb commented Feb 2, 2015

when #209 is merged i'll rebase, for a tidier history on this one

@jondeandres
Copy link
Contributor

Thanks @jjb. Tests are failing cause sidekiq is not supported in Ruby 1.8.7, take a look at our gemspec file, https://github.com/rollbar/rollbar-gem/blob/master/rollbar.gemspec#L25.

@jjb jjb force-pushed the refactor-sidekiq-handler branch 4 times, most recently from c76588a to a95b4ea Compare February 4, 2015 02:37
@jjb
Copy link
Contributor Author

jjb commented Feb 4, 2015

@jondeandres 1.8.6 stuff is fixed now.

any idea why this lone failure happened? https://travis-ci.org/rollbar/rollbar-gem/jobs/49406361

/home/travis/.rvm/gems/ruby-2.1.0/gems/genspec-0.2.7/lib/genspec.rb:8:in `<top (required)>': Unsupported Rails version: 4.0.4 (RuntimeError)
    from /home/travis/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
    from /home/travis/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'

@jondeandres
Copy link
Contributor

@jjb is because the version of genspec:

0.2.7 https://github.com/sinisterchipmunk/genspec/blob/v0.2.7/lib/genspec.rb
0.2.8 https://github.com/sinisterchipmunk/genspec/blob/v0.2.8/lib/genspec.rb

It seems to not be crashing in master, so probably is something in your branch. You can change gemfiles/rails40.gemfile and check that is solved:

gem 'genspec', '> 0.2.7'

@jjb
Copy link
Contributor Author

jjb commented Feb 4, 2015

@jondeandres gotcha. i increased the version for the whole project, no reason to not do this right?

(after it runs i'll check it to only be for rails 4 if you prefer that)

@jondeandres
Copy link
Contributor

Nice!

One comment in specs. Can you replace this style in general?

let(:foo){:bar} to let(:foo) { :bar }

This covers the core functionality of the handler.

Here are ways the tests could be further improved, which I deemed not worth the effort:

1. Testing if the handler is attached properly for Rails < 3 vs. >=3. I have tested it manually for the >=3 case and it works.

2. higher level functional test in the style of how DelayedJob is tested, where actual failing jobs are queued up:
  https://github.com/rollbar/rollbar-gem/blob/master/spec/rollbar/delayed_job_spec.rb

I didn't do this because it's more difficult to do with Sidekiq, for reasons explored here:
  sidekiq/sidekiq#2128
@jjb
Copy link
Contributor Author

jjb commented Feb 5, 2015

@jondeandres all set

require 'rollbar/sidekiq'
end

describe "Sidekiq integration", :reconfigure_notifier => false do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be describe Rollbar::Sidekiq.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it will blow up under 1.8.7 because that class isn't loaded in lines 3-6 above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm! And can we use an string here then instead of a constant?

@jjb
Copy link
Contributor Author

jjb commented Feb 5, 2015

@jondeandres perhaps it will be more efficient for you to simply fork my branch and make the style changes you want? It's probably faster to make the changes directly than to explain to me the rationale.

@jondeandres
Copy link
Contributor

@jjb yah! probably! I'll fork this and make a PR to your repo. I hope we can merge this today. Sorry for this style comments, it's just to maintain some order here :-D.

@jjb
Copy link
Contributor Author

jjb commented Feb 5, 2015

no problem, i enjoyed the process.

@jjb
Copy link
Contributor Author

jjb commented Feb 5, 2015

@jondeandres merged

@jondeandres
Copy link
Contributor

Nice! Thanks @jjb for this!

@jjb
Copy link
Contributor Author

jjb commented Feb 5, 2015

@jondeandres were you going to merge this one today?

jondeandres added a commit that referenced this pull request Feb 5, 2015
@jondeandres jondeandres merged commit d1289b2 into rollbar:master Feb 5, 2015
@jondeandres
Copy link
Contributor

Merged, thanks @jjb!!

@jjb
Copy link
Contributor Author

jjb commented Feb 5, 2015

🍆

@jjb jjb deleted the refactor-sidekiq-handler branch February 5, 2015 23:07
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.

3 participants