README.md in rufus-scheduler-3.0.4 vs README.md in rufus-scheduler-3.0.5

- old
+ new

@@ -364,11 +364,11 @@ end ``` The :timeout option accepts either a duration (like "1d" or "2w3d") or a point in time (like "2013/12/12 12:00"). -### :first_at, :first_in, :first +### :first_at, :first_in, :first, :first_time This option is for repeat jobs (cron / every) only. It's used to specify the first time after which the repeat job should trigger for the first time. @@ -391,10 +391,38 @@ ```ruby job.first_at = Time.now + 10 job.first_at = Rufus::Scheduler.parse('2029-12-12') ``` +The first argument (in all its flavours) accepts a :now or :immediately value. That schedules the first occurence for immediate triggering. Consider: + +```ruby +require 'rufus-scheduler' + +s = Rufus::Scheduler.new + +n = Time.now; p [ :scheduled_at, n, n.to_f ] + +s.every '3s', :first => :now do + n = Time.now; p [ :in, n, n.to_f ] +end + +s.join + +``` + +that'll output something like: + +``` +[:scheduled_at, 2014-01-22 22:21:21 +0900, 1390396881.344438] +[:in, 2014-01-22 22:21:21 +0900, 1390396881.6453865] +[:in, 2014-01-22 22:21:24 +0900, 1390396884.648807] +[:in, 2014-01-22 22:21:27 +0900, 1390396887.651686] +[:in, 2014-01-22 22:21:30 +0900, 1390396890.6571937] +... +``` + ### :last_at, :last_in, :last This option is for repeat jobs (cron / every) only. It indicates the point in time after which the job should unschedule itself. @@ -668,9 +696,47 @@ job.keys # => [ :timestamp, :counter ] ``` Job-local variables are thread-safe. + +### call + +Job instances have a #call method. It simply calls the scheduled block or callable immediately. + +```ruby +job = + @scheduler.schedule_every '10m' do |job| + # ... + end + +job.call +``` + +Warning: the Scheduler#on_error handler is not involved. Error handling is the responsibility of the caller. + +If the call has to be rescued by the error handler of the scheduler, ```call(true)``` might help: + +```ruby +require 'rufus-scheduler' + +s = Rufus::Scheduler.new + +def s.on_error(job, err) + p [ 'error in scheduled job', job.class, job.original, err.message ] +rescue + p $! +end + +job = + s.schedule_in('1d') do + fail 'again' + end + +job.call(true) + # + # true lets the error_handler deal with error in the job call +``` ## AtJob and InJob methods ### time