lib/resque/scheduler.rb in resque-scheduler-2.0.0.h vs lib/resque/scheduler.rb in resque-scheduler-2.0.0
- old
+ new
@@ -15,20 +15,20 @@
# If set, produces no output
attr_accessor :mute
# If set, will try to update the schulde in the loop
attr_accessor :dynamic
-
+
# Amount of time in seconds to sleep between polls of the delayed
# queue. Defaults to 5
attr_writer :poll_sleep_amount
# the Rufus::Scheduler jobs that are scheduled
def scheduled_jobs
@@scheduled_jobs
end
-
+
def poll_sleep_amount
@poll_sleep_amount ||= 5 # seconds
end
# Schedule all jobs and continually look for delayed jobs (never returns)
@@ -73,11 +73,11 @@
rescue ArgumentError
warn "Signals QUIT and USR1 and USR2 not supported."
end
end
- def print_schedule
+ def print_schedule
if rufus_scheduler
log! "Scheduling Info\tLast Run"
scheduler_jobs = rufus_scheduler.all_jobs
scheduler_jobs.each do |k, v|
log! "#{v.t}\t#{v.last}\t"
@@ -87,11 +87,11 @@
# Pulls the schedule from Resque.schedule and loads it into the
# rufus scheduler instance
def load_schedule!
procline "Loading Schedule"
-
+
# Need to load the schedule from redis for the first time if dynamic
Resque.reload_schedule! if dynamic
log! "Schedule empty! Set Resque.schedule" if Resque.schedule.empty?
@@ -101,11 +101,11 @@
load_schedule_job(name, config)
end
Resque.redis.del(:schedules_changed)
procline "Schedules Loaded"
end
-
+
# modify interval type value to value with options if options available
def optionizate_interval_value(value)
args = value
if args.is_a?(::Array)
return args.first if args.size > 2 || !args.last.is_a?(::Hash)
@@ -153,11 +153,10 @@
end
# Handles queueing delayed items
# at_time - Time to start scheduling items (default: now).
def handle_delayed_items(at_time=nil)
- item = nil
if timestamp = Resque.next_delayed_timestamp(at_time)
procline "Processing Delayed Items"
while !timestamp.nil?
enqueue_delayed_items_for_timestamp(timestamp)
timestamp = Resque.next_delayed_timestamp(at_time)
@@ -182,11 +181,11 @@
def handle_shutdown
exit if @shutdown
yield
exit if @shutdown
end
-
+
def handle_errors
begin
yield
rescue Exception => e
log! "#{e.class.name}: #{e.message}"
@@ -217,10 +216,10 @@
# hack to avoid havoc for people shoving stuff into queues
# for non-existent classes (for example: running scheduler in
# one app that schedules for another
if Class === klass
ResqueScheduler::Plugin.run_before_delayed_enqueue_hooks(klass, *params)
- Resque.enqueue(klass, *params)
+ Resque.enqueue_to(queue, klass, *params)
else
# This will not run the before_hooks in rescue, but will at least
# queue the job.
Resque::Job.create(queue, klass, *params)
end