Permalink
Browse files

Reimplement Sidekiq worker

This better integrates various Sidekiq features into AJ jobs.

Things like the JID will be set as expected and the user can use `sidekiq_options` in AJ::Base subclasses as usual to configure various features.
  • Loading branch information...
1 parent c6925f5 commit c813a30c5a3031108bdd41b57571803c13f95569 @mperham mperham committed May 20, 2014
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/active_job/queue_adapters/sidekiq_adapter.rb
View
11 lib/active_job/queue_adapters/sidekiq_adapter.rb
@@ -5,17 +5,24 @@ module QueueAdapters
class SidekiqAdapter
class << self
def queue(job, *args)
- JobWrapper.client_push class: JobWrapper, queue: job.queue_name, args: [ job, *args ]
+ item = { 'class' => JobWrapper, 'queue' => job.queue_name, 'args' => [job, *args] }
+ Sidekiq::Client.push(job.get_sidekiq_options.merge(item))
end
end
class JobWrapper
include Sidekiq::Worker
def perform(job_name, *args)
- job_name.constantize.new.perform *Parameters.deserialize(args)
+ instance = job_name.constantize.new
+ instance.jid = self.jid
+ instance.perform *Parameters.deserialize(args)
end
end
end
end
end
+
+class ActiveJob::Base
+ include Sidekiq::Worker
+end

0 comments on commit c813a30

Please sign in to comment.