lib/resque/scheduler.rb in resque-scheduler-1.9.6 vs lib/resque/scheduler.rb in resque-scheduler-1.9.7
- old
+ new
@@ -58,18 +58,25 @@
# required for the jobs to be scheduled. If rails_env is missing, the
# job should be scheduled regardless of what ENV['RAILS_ENV'] is set
# to.
if config['rails_env'].nil? || rails_env_matches?(config)
log! "Scheduling #{name} "
- if !config['cron'].nil? && config['cron'].length > 0
- rufus_scheduler.cron config['cron'] do
- log! "queuing #{config['class']} (#{name})"
- enqueue_from_config(config)
+ interval_defined = false
+ interval_types = %w{cron every}
+ interval_types.each do |interval_type|
+ if !config[interval_type].nil? && config[interval_type].length > 0
+ rufus_scheduler.send(interval_type, config[interval_type]) do
+ log! "queueing #{config['class']} (#{name})"
+ enqueue_from_config(config)
+ end
+ interval_defined = true
+ break
end
- else
- log! "no cron found for #{config['class']} (#{name}) - skipping"
end
+ unless interval_defined
+ log! "no #{interval_types.join(' / ')} found for #{config['class']} (#{name}) - skipping"
+ end
end
end
end
# Returns true if the given schedule config hash matches the current
@@ -77,13 +84,14 @@
def rails_env_matches?(config)
config['rails_env'] && ENV['RAILS_ENV'] && config['rails_env'].gsub(/\s/,'').split(',').include?(ENV['RAILS_ENV'])
end
# Handles queueing delayed items
- def handle_delayed_items
- item = nil
+ # at_time - Time to start scheduling items (default: now).
+ def handle_delayed_items(at_time=nil)
+ timestamp = nil
begin
- if timestamp = Resque.next_delayed_timestamp
+ if timestamp = Resque.next_delayed_timestamp(at_time)
enqueue_delayed_items_for_timestamp(timestamp)
end
# continue processing until there are no more ready timestamps
end while !timestamp.nil?
end