John Wells wrote:
> On Wed, Feb 20, 2008 at 6:36 PM, Yves-Eric Martin
> <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
>
> Thanks! It's a good idea, but unfortunately, I only want cleanup to
> happen when the worker is forceably deleted...not when it exits on its
> own. Ensure would cleanup in both cases.
Well that one is easily taken care of: just use a local variable to
indicate whether the processing was interrupted or went to completion.
You would probably simply use a boolean or constant integers to indicate
the exit status, but I'll write it here with a string for simplicity:
class FooWorker < BackgrounDRb::MetaWorker
def some_work(args=nil)
job_exit_status = 'FORCEABLY_DELETED'
begin
# Large batch job here
...
rescue
job_exit_status = 'ERRORED_OUT'
# Error processing here
...
else
job_exit_status = 'FINISHED_NORMALLY'
ensure
case job_exit_status
when 'FINISHED_NORMALLY'
# Your normal ending cleanup code here
...
when 'ERRORED_OUT'
# Your error ending cleanup code here
...
else
# Your "delete_worker" ending cleanup code here
...
end
end
end
end
Of course this still all assumes that delete_worker is *not* the "kill
-9" hemant suggested, and that it will let your ensure clause run. Have
you tried it out yet? Let us know how it goes.
Cheers,
--
Yves-Eric
_______________________________________________
Backgroundrb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/backgroundrb-devel