Internetbureau Holder

Adding Hoptoad support to Delayed::Job

Stephan Kaag di 16 mrt 10

Altough Hoptoad might be installed in your Rails application, the errors that are raised within delayed-jobs will not be reported to this excellent service.

Why is that? Delayed-job has it’s own exception rescuing mechanism and the Hoptoad hook isn’t called by default. If you want to report all delayed-job’s exceptions to Hoptoad you can use a hook-script like this.

begin
  Delayed::Job.logger.info "Adding Hoptoad support to Delayed::Job"
  begin
    module Delayed
      class Job
        
        def invoke_job_with_hoptoad
          if defined?(HoptoadNotifier)
            Delayed::Job.send(:define_method, :invoke_job_with_hoptoad) do
              begin
                invoke_job_without_hoptoad
              rescue Exception => e
                HoptoadNotifier.notify(e, :cgi_data => self.attributes)
                raise e
              end
            end
          else
            Delayed::Job.send(:define_method, :invoke_job_with_hoptoad) do
              invoke_job_without_hoptoad
            end
          end
          invoke_job_with_hoptoad
        end
        
        alias_method_chain :invoke_job, :hoptoad
        
      end # Job
    end # Delayed
  rescue Exception => e
    Delayed::Job.logger.error(e)
    raise e
  end
end

Gepost in hor |  0 reacties

Plaats je reactie





Welcome to Holland On Rails

This weblog is the official Ruby techblog from the guys at Holder, a Ruby development company. Holder is also the company behind the RubyAndRails Europe Conference in Amsterdam.

Recente Jobs


Bekijk alle jobs »»

Gereedschapskist

Onmisbare tools voor
iedere developer!
Ruby On Rails
Framework voor de web 2.0 developer. Eindelijk vooruitgang!
TextMate
Editor for true pro's
Typ, tab, top :-)
Nee, niet voor Win.
Made On A Mac
En nou is het over met die saaie grijze Windows bak van je!

Auteurs op deze site

Chris Obdam

'Less is more' evangelist, past dit ook dagelijks toe op zijn tandenborstel.

Chiel Wester

Snelheidswonder op Ruby wielen. Leuk om mee te pair-programmen ;-) Recommend Me

Stephan Kaag

Het eerste Rails coreteam- member uit Nederland? Rails evangelist van het eerste uur.

Paul Engel

Én Rails programmeren én interfaces designen? Je zou hem superman kunnen noemen..

Dax Huiberts

Official Zip-Programmer, skinny code is helemaal zijn ding. Haalt meer code weg dan dat er bij komt.

Freek Monteban

Het nieuwste telg uit het Holland on Rails nest! Hij doet niets anders meer!

Johan Vermeulen

De stylesheet-koning uit de kop van Noord-Holland!