class Rufus::Scheduler

def schedule_every (freq, params={}, &block)


end
# won't get rescheduled in case of exception
do_some_prone_to_error_stuff()
scheduler.schedule_every "500", :try_again => false do

want the job to be rescheduled, set the parameter :try_again to false.
In case of exception in the job, it will be rescheduled. If you don't

the job.
This method returns a job identifier which can be used to unschedule()

before the time specified in 'freq'.
Schedules a job in a loop. After an execution, it will not execute
def schedule_every (freq, params={}, &block)
    f = duration_to_f freq
    params = prepare_params params
    schedulable = params[:schedulable]
    params[:every] = freq
    last_at = params[:last_at]
    next_at = if last_at
        last_at + f
    else
        Time.now.to_f + f
    end
    do_schedule_at(next_at, params) do |job_id, at|
        #
        # trigger ...
        hit_exception = false
        begin
            if schedulable
                schedulable.trigger params
            else
                block.call job_id, at, params
            end
        rescue Exception => e
            log_exception e
            hit_exception = true
        end
        # cannot use a return here !!! (block)
        unless \
            @dont_reschedule_every or
            (params[:dont_reschedule] == true) or
            (hit_exception and params[:try_again] == false)
            #
            # ok, reschedule ...
            params[:job_id] = job_id
            params[:last_at] = at
            
            schedule_every params[:every], params, &block
                #
                # yes, this is a kind of recursion
                # note that params[:every] might have been changed
                # by the block/schedulable code
        end
        job_id
    end
end