class Rufus::Scheduler

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


end
# schedule something every two days, start in 5 hours...
scheduler.schedule_every "2d", :first_in => "5h" do

accepted.
Since rufus-scheduler 1.0.2, the params :first_at and :first_in are

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
  first_at = params.delete :first_at
  first_in = params.delete :first_in
  previous_at = params[:previous_at]
  next_at = if first_at
    first_at
  elsif first_in
    Time.now.to_f + duration_to_f(first_in)
  elsif previous_at
    previous_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[:previous_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