If for some reason (external and temporary) a job needs to be released, there could be a way (other than raising an Interrupt
) to catch some exception and interpreting it as to release the job with specific options.
This should go with a way to distinguish in code whether it's executed by the worker or by passenger/whatever, as in the following example code
module AsyncMethods
def anything(*args)
do_something
rescue => some_controlled_situation
if defined(ASYNC_OBSERVER_WORKER)
raise AsyncObserver::Release :delay => 10
else
async_send_opts :anything, {:delay => 10}, args
end
end
end