Scheduled Jobs with ActiveJob

1,288 views
Skip to first unread message

jan javinto

unread,
Jun 12, 2015, 6:00:30 AM6/12/15
to sid...@googlegroups.com
Hi,

I followed the guide https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs to run Jobs with Sidekiq and Whenever.

I'm on Rails 4.2 and have my Jobs converted into ActiveJob format. All jobs work fine when executed normally. But not from my Cron Tabfile.

If I follow the guide above Sidekiq runs into the following message: undefined method `jid=' for #<SendNotificationsJob:0x007fa0b9b7d818>

It looks like as the runner has no idea as where to find that job. I tried using require 'app/jobs/send_notifications_job' but without any luck.

How to adjust the sidekiq_pusher script to be compatible with ActiveJob ?

Thanks

Jan

Mike Perham

unread,
Jun 12, 2015, 6:53:21 PM6/12/15
to sid...@googlegroups.com
Can you show us the exact code of your script and the backtrace?
--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.
To post to this group, send email to sid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sidekiq/8f3ea9bc-b26d-4d23-884c-eb3340eb3ddd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jan javinto

unread,
Jun 15, 2015, 6:31:40 AM6/15/15
to sid...@googlegroups.com
scripts/sidekiq_pusher.rb:

klass = ARGV[0]
require 'sidekiq'
Sidekiq.configure_client do |config|
  config.redis = { url: "redis://localhost:6379", namespace: 'zvjavinto' }
end
Sidekiq::Client.push('class' => klass, 'args' => [])


app/jobs/send_notifications_jobs.rb:

class SendNotificationsJob < ActiveJob::Base
   def perform
      logger.debug "running the job"
   end
end

From my terminal:
bundle exec scripts/sidekiq_pusher.rb SendNotificationsJob

Then my SideKiq terminal now reports:
2015-06-15T10:28:54.633Z 2689 TID-ovpxw5rn0 WARN: {"class"=>"SendNotificationsJob", "args"=>[], "retry"=>true, "queue"=>"default", "jid"=>"c96b07e67b6672f13c325f78", "enqueued_at"=>1434364117.0195909}
2015-06-15T10:28:54.633Z 2689 TID-ovpxw5rn0 WARN: undefined method `jid=' for #<SendNotificationsJob:0x007fadde7f3670>
2015-06-15T10:28:54.633Z 2689 TID-ovpxw5rn0 WARN: /Users/javinto/.rvm/gems/ruby-2.2.2@rails4/gems/sidekiq-3.3.4/lib/sidekiq/processor.rb:48:in `process'
/Users/javinto/.rvm/gems/ruby-2.2.2@rails4/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
/Users/javinto/.rvm/gems/ruby-2.2.2@rails4/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
/Users/javinto/.rvm/gems/ruby-2.2.2@rails4/gems/celluloid-0.16.0/lib/celluloid/calls.rb:122:in `dispatch'
/Users/javinto/.rvm/gems/ruby-2.2.2@rails4/gems/celluloid-0.16.0/lib/celluloid/cell.rb:60:in `block in invoke'
/Users/javinto/.rvm/gems/ruby-2.2.2@rails4/gems/celluloid-0.16.0/lib/celluloid/cell.rb:71:in `block in task'
/Users/javinto/.rvm/gems/ruby-2.2.2@rails4/gems/celluloid-0.16.0/lib/celluloid/actor.rb:357:in `block in task'
/Users/javinto/.rvm/gems/ruby-2.2.2@rails4/gems/celluloid-0.16.0/lib/celluloid/tasks.rb:57:in `block in initialize'
/Users/javinto/.rvm/gems/ruby-2.2.2@rails4/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'

Hopefully that will do.

Thanks.



Op zaterdag 13 juni 2015 00:53:21 UTC+2 schreef Mike Perham:

Mike Perham

unread,
Jun 15, 2015, 9:22:54 AM6/15/15
to sid...@googlegroups.com
Ah, you can't do that with AJ. Only native Workers. 

Mike Perham

unread,
Jun 15, 2015, 10:53:16 AM6/15/15
to sid...@googlegroups.com
Let me rephrase that: you can't do it with Sidekiq's native API.  You'll need to do `klass.constantize.perform_later` instead of Sidekiq::Client.push.
--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

jan javinto

unread,
Jun 17, 2015, 10:20:45 AM6/17/15
to sid...@googlegroups.com
That's loud and clear!

So in order to use jobs right from the application as well as via Whenever I added "include Sidekiq::Worker" to my ActiveJobs. So:

class MyJob < ActiveJob::Base
  include Sidekiq::Worker

I'm not sure how sustainable it is, but it works from both sides.

I can now use the 'original' sidekiq_pusher.rb script.

Thanks!!

Op maandag 15 juni 2015 16:53:16 UTC+2 schreef Mike Perham:
Reply all
Reply to author
Forward
0 new messages