Class: Rake::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_notifier.rb

Instance Method Summary collapse

Instance Method Details

#execute(args = nil) ⇒ Object



12
13
14
15
16
# File 'lib/rake_notifier.rb', line 12

def execute(args=nil)
  orig_execute(args)
rescue Exception => exception
  handle_exception(exception)
end

#handle_exception(exception) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rake_notifier.rb', line 18

def handle_exception(exception)
  if Rake.email_from.blank? # lazy load
    # fetch emails from ExceptionNotifier's configuration
    if defined? ExceptionNotifier
      args = Rails::Application.subclasses.map {|app| app.config.middleware.middlewares }.flatten.select {|m| m === ExceptionNotifier }.map {|en| en.args }.flatten
      if args.blank?
        raise "Please setup your ExceptionNotifier first"
      else
        Rake.email_from = args[0][:sender_address]
        Rake.email_to   = args.map {|i| i[:exception_recipients] }.flatten.join(", ")
      end
    end
  end

  $stderr.puts
  $stderr.puts subject = "Rake exception - #{exception.message}"
  $stderr.puts body = "#{exception.message}\n\n#{exception.backtrace.join("\n")}"
  Pony.mail(:from => Rake.email_from, :to => Rake.email_to, :subject => subject, :body => body)
  $stderr.puts
  $stderr.puts "Exception details sent to #{Rake.email_to}"
  $stderr.puts
end

#orig_executeObject



11
# File 'lib/rake_notifier.rb', line 11

alias :orig_execute :execute