I ended up creating a ''RobustWorker'', which all our workers
subclass.
Then the methods use notify_on_failure :tries => 5 do work; end
That method runs the block in a begin rescue, up to five times,
sending me an email if it is never successful. Of course, any db work
should be done in a transaction.
HTH
Adam Williams
On Jun 23, 2009, at 6:27 AM, Tobias Overkamp <tov-backgroundrb at
overkamp.org
> wrote:
> Hi folks!
> I''m still starting with BackgroundRB and I wonder if it is
possible
> to to put some kind of exception handling (begin/rescue etc.) around
> each method in my worker.
>
> In the example below I want to make sure that the whole method could
> be processed correctly before I commit the data in the database.
> Of course I don''t want to write the begin-rescue idiom in every
> method (DRY). Is there some kind of hook/callback that I''m
missing?
>
> Sample:
>
> class TransferWorker < BackgrounDRb::MetaWorker
> set_worker_name :transfer_worker
>
>
> def request_transfer_from_registry
>
> begin
> ActiveRecord::Base.transaction do
> transfer = Order::OrderTransfer.new(:xml => args[:xml])
> transfer.fetch_from_xml_by_id
> end
> rescue Exception => e
> #notify whomever...
> end
>
> end
>
> end
>
>
> Regards,
>
> Tobias
> _______________________________________________
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel