require 'rufus/scheduler'

class Rufus::Scheduler::Job

  alias_method :old_do_call, :do_call
  def do_call(time, do_rescue)
    args = [ self, time ][0, @callable.arity]
    @callable.call(*args)
  rescue StandardError => se
    raise se unless do_rescue
    return if se.is_a?(KillSignal) # discard
    @scheduler.on_error(self, se)
  ensure
    ActiveRecord::Base.clear_active_connections!
  end

end