socialpandas / sidekiq-superworker

Directed acyclic graphs of Sidekiq jobs
MIT License
438 stars 34 forks source link

Custom sidekiq integration error #12

Closed nazarhussain closed 10 years ago

nazarhussain commented 10 years ago

Hi,

In my project I am using sidekiq in a custom way. I was not calling perform_async on workers, instead was directly pushing jobs to redis server.

Sidekiq::Client.push(
            {
                class: "#{actor}SuperWorker",
                args: ["#{event}", actor_id]
            }.stringify_keys
        )

It was working perfectly fine with normal sidekiq workers. But when I use the same method with superworkers it gives me following error:

2014-02-23T21:57:41Z 18278 TID-nrqp4 WARN: undefined method `jid=' for #<UserSuperWorker:0x00000004c24bc0>
2014-02-23T21:57:41Z 18278 TID-nrqp4 WARN: /home/user/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/sidekiq-2.17.6/lib/sidekiq/processor.rb:45:in `block in process'
/home/user/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `call'
/home/user/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `public_send'
/home/user/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `dispatch'
/home/user/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/celluloid-0.15.2/lib/celluloid/calls.rb:67:in `dispatch'
/home/user/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/celluloid-0.15.2/lib/celluloid/future.rb:14:in `block in new'
/home/user/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/celluloid-0.15.2/lib/celluloid/thread_handle.rb:13:in `block in initialize'
/home/user/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/celluloid-0.15.2/lib/celluloid/internal_pool.rb:100:in `call'
/home/user/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/celluloid-0.15.2/lib/celluloid/internal_pool.rb:100:in `block in create'

Can you explain me the way I can interact with superworkers using sidekiq client not the actual worker class.

tombenner commented 10 years ago

Superworker jobs never touch Redis and are stored as ActiveRecord records instead, so you can't expect them to initialize them like normal Sidekiq jobs. You'll need to use perform_async, which should be very doable. Your code could be rewritten like this, for example:

superworker = "#{actor}SuperWorker".constantize
superworker.perform_async("#{event}", actor_id)