[Backgroundrb-devel] email on error

Ryan Leavengood leavengood at gmail.com
Thu Mar 6 16:51:57 EST 2008


On Thu, Mar 6, 2008 at 3:30 PM, Ian Smith-Heisters
<heisters at greenriver.org> wrote:
>
>  I'm trying to figure out how to use exception_notification to alert me
>  of any error in bdrb. I'm not quite sure how bdrb handles errors,
>  though. It seems like implementing ExceptionNotifiable in my worker
>  class would catch any worker errors (maybe). But what if bdrb fails
>  before it loads the worker, or there some other internal bdrb error?
>  It seems to catch everything and put it in backgroundrb_debug.log, is
>  it possible to exploit whatever hook that uses?
>
>  I'll play around with it and RTFS, but I was just hoping someone might
>  have some prior experience with this.

I wanted something like this too and what I did was add some methods
to BackgrounDRb::MetaWorker like so:

class BackgrounDRb::MetaWorker
  def handle_exceptions
    result = nil

    if block_given?
      begin
        result = yield
      rescue Exception => e
        log_error(e)
      end
    end

    result
  end

  def log_error(error)
    case error
    when Exception
      class_name = self.class.name
      logger.info("Had exception #{error.class} in #{class_name},
sending email.")
      NotifyMailer.deliver_error_notification(error, class_name)
    else
      logger.info(error.to_s)
    end
  end
end

I put the above in a file in lib. I require it in my workers and then
call handle_exceptions with a block inside my worker methods. This
definitely works, though I don't know if it is the ideal way to do it.
For one thing it won't catch errors at the level of BackgrounDRb
itself. But at least for worker errors it is fine. Also as you can see
I defined my own error mailer that is very similar to the one from the
ExceptionNotifier plug-in.

It might be nice for BackgrounDRb to support something like this
itself. Maybe one of us could put together a patch.

Also I use the above with the last released version of BackgrounDRb, I
haven't yet upgraded. Though it will probably also work with the new
version.

Ryan


More information about the Backgroundrb-devel mailing list