lib/rekiq/scheduler.rb in rekiq-0.9.3 vs lib/rekiq/scheduler.rb in rekiq-1.0.0
- old
+ new
@@ -1,42 +1,39 @@
module Rekiq
class Scheduler
- def initialize(worker_name, queue, args, job, addon, cancel_args)
+ def initialize(worker_name, queue, args, contract)
@worker_name = worker_name
@queue = queue
@args = args
- @job = job
- @addon = addon
- @cancel_args = cancel_args
+ @contract = contract
end
- def schedule(from = Time.now)
- @work_time = @job.next_work_time(from)
-
- @work_time.nil? ? nil : [schedule_work, @work_time]
+ def schedule_initial_work(from = Time.now)
+ @work_time = @contract.initial_work_time(from)
+ schedule_work
end
- def schedule_from_work_time(from)
- @work_time = @job.next_work_time_from_work_time(from)
-
- @work_time.nil? ? nil : [schedule_work, @work_time]
+ def schedule_next_work(previous_work_time)
+ @work_time = @contract.next_work_time(previous_work_time)
+ schedule_work
end
- private
+ protected
def schedule_work
+ @work_time.nil? ? nil : [push_to_redis, @work_time]
+ end
+
+ def push_to_redis
client_args = {
- 'at' => @work_time.to_f,
- 'queue' => @queue,
- 'class' => @worker_name,
- 'args' => @args,
- 'rq:job' => @job.to_array,
- 'rq:at' => @work_time.to_f,
- 'rq:schdlr' => nil
- }.tap do |hash|
- hash['rq:addon'] = @addon unless @addon.nil?
- hash['rq:ca'] = @cancel_args unless @cancel_args.nil?
- end
+ 'at' => @work_time.to_f,
+ 'queue' => @queue,
+ 'class' => @worker_name,
+ 'args' => @args,
+ 'rq:ctr' => @contract.to_hash,
+ 'rq:sdl' => nil,
+ 'rq:at' => @work_time.to_f # this needs to be here because the key 'at' is removed by sidekiq
+ }
Sidekiq::Client.push(client_args)
end
end
end
\ No newline at end of file