2014-05-18 15:02:02 -04:00
|
|
|
require 'sidekiq'
|
|
|
|
|
|
|
|
module ActiveJob
|
|
|
|
module QueueAdapters
|
|
|
|
class SidekiqAdapter
|
|
|
|
class << self
|
2014-05-20 19:07:45 -04:00
|
|
|
def enqueue(job, *args)
|
2014-05-29 12:29:33 -04:00
|
|
|
#Sidekiq::Client does not support symbols as keys
|
2014-05-20 11:37:10 -04:00
|
|
|
Sidekiq::Client.push \
|
|
|
|
'class' => JobWrapper,
|
|
|
|
'queue' => job.queue_name,
|
|
|
|
'args' => [ job, *args ],
|
|
|
|
'retry' => true
|
2014-05-19 06:34:27 -04:00
|
|
|
end
|
2014-05-19 18:27:28 -04:00
|
|
|
|
2014-05-20 19:07:45 -04:00
|
|
|
def enqueue_at(job, timestamp, *args)
|
2014-05-20 12:13:28 -04:00
|
|
|
Sidekiq::Client.push \
|
|
|
|
'class' => JobWrapper,
|
|
|
|
'queue' => job.queue_name,
|
|
|
|
'args' => [ job, *args ],
|
2014-05-20 13:17:10 -04:00
|
|
|
'retry' => true,
|
|
|
|
'at' => timestamp
|
2014-05-19 18:27:28 -04:00
|
|
|
end
|
2014-05-19 06:34:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class JobWrapper
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform(job_name, *args)
|
2014-08-18 09:09:04 -04:00
|
|
|
job_name.constantize.new.execute(*args)
|
2014-05-18 15:02:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|