Airbrake notification in Rake tasks

Updated . Posted . Visible to the public.

Put

def task_with_hoptoad_notification(options)
  task(options) do
    begin
      yield
    rescue Exception => e
      Airbrake.notify(e)
      raise e
    end
  end
end

at the top of the Rakefile, and replace all relevant

task :my_task => :environment do
    do_something
end

with

task_with_hoptoad_notification :my_task => :environment do
    do_something
end

This will use the usual notification rules, i.e. you won't get anything in the development or test environments.

Obiously, this only works with tasks that actually depend on :environment.

Profile picture of Tobias Kraze
Tobias Kraze
Last edit
Keywords
exception
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2010-09-07 14:06)