README.md in rufus-scheduler-3.2.1 vs README.md in rufus-scheduler-3.2.2

- old
+ new

@@ -121,11 +121,11 @@ * [I want a refund](http://blog.nodejitsu.com/getting-refunds-on-open-source-projects) * [Passenger and rufus-scheduler](http://stackoverflow.com/questions/18108719/debugging-rufus-scheduler/18156180#18156180) * [Passenger and rufus-scheduler (2)](http://stackoverflow.com/questions/21861387/rufus-cron-job-not-working-in-apache-passenger#answer-21868555) * [Passenger in-depth spawn methods](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/) * [Passenger in-depth spawn methods (smart spawning)](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/#smart-spawning-hooks) -* [The scheduler comes up when running the Rails console](https://github.com/jmettraux/rufus-scheduler#avoid-scheduling-when-running-the-ruby-on-rails-console) +* [The scheduler comes up when running the Rails console or a Rake task](https://github.com/jmettraux/rufus-scheduler#avoid-scheduling-when-running-the-ruby-on-rails-console) * [I don't get any of this, I just want it to work in my Rails application](#so-rails) ## scheduling @@ -179,11 +179,11 @@ Interval jobs, trigger, execute and then trigger again after the interval elapsed. (every jobs time between trigger times, interval jobs time between trigger termination and the next trigger start). Cron jobs are based on the venerable cron utility (```man 5 crontab```). They trigger following a pattern given in (almost) the same language cron uses. -#### +#### ### #schedule_x vs #x schedule_in, schedule_at, schedule_cron, etc will return the new Job instance. @@ -639,18 +639,37 @@ ``` ### last_time Returns the last time the job triggered (is usually nil for AtJob and InJob). -k ```ruby -job = scheduler.schedule_every('1d') do; end -# ... +job = scheduler.schedule_every('10s') do; end + job.scheduled_at # => 2013-07-17 23:48:54 +0900 +job.last_time + # => nil (since we've just scheduled it) + +# after 10 seconds + +job.scheduled_at + # => 2013-07-17 23:48:54 +0900 (same as above) +job.last_time + # => 2013-07-17 23:49:04 +0900 ``` +### previous_time + +Returns the previous `#next_time` +```ruby +scheduler.every('10s') do |job| + puts "job scheduled for #{job.previous_time} triggered at #{Time.now}" + puts "next time will be around #{job.next_time}" + puts "." +end +``` + ### last_work_time, mean_work_time The job keeps track of how long its work was in the `last_work_time` attribute. For a one time job (in, at) it's probably not very useful. The attribute `mean_work_time` contains a computed mean work time. It's recomputed after every run (if it's a repeat job). @@ -1447,22 +1466,24 @@ ### avoid scheduling when running the Ruby on Rails console (Written in reply to https://github.com/jmettraux/rufus-scheduler/issues/186 ) -If you don't want rufus-scheduler to kick in when running the Ruby on Rails console, you can wrap your initializer in a conditional: +If you don't want rufus-scheduler to kick in when running the Ruby on Rails console or invoking a rake task, you can wrap your initializer in a conditional: ```ruby # # config/initializers/scheduler.rb require 'rufus-scheduler' s = Rufus::Scheduler.singleton -unless defined?(Rails::Console) +unless defined?(Rails::Console) || File.split($0).last == 'rake' + # only schedule when not running from the Ruby on Rails console + # or from a rake task s.every '1m' do Rails.logger.info "hello, it's #{Time.now}" Rails.logger.flush