1. Jan 31st, 2010

    Snipped: send email notification when Resque worker fails

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    module Resque
      module Failure
        # Store a copy of the failure in Redis, so we have access from the UI. Also
        # send an email to the developer, so we know something went foul.
        class Notifier < Base
          def save
            # Store in Redis
            super
            # Create notification email
            email = TMail::Mail.new
            email.to = ".. your email here .."
            email.subject = "[Error] #{exception}"
            email.body = <<-EOF
    Queue:    #{queue}
    Worker:   #{worker}
     
    #{payload.inspect}
     
    #{exception}
    #{exception.backtrace.join("\n")}
            EOF
            Mailer.deliver email
          rescue
          end
        end
      end
    end
     
    Resque::Failure.backend = Resque::Failure::Notifier if ENV['RAILS_ENV'] == "production"
    Your comment, here ⇓