3

I am using Ruby on Rails 5.2.0 to develop a system and I need to run a job every 2 minute. I'm using sidekiq for background processing and sidekiq-cron for scheduling jobs.

I execute the following line in rails console:

job=Sidekiq::Cron::Job.new( name: 'TestWorker_Job', cron: '*/2 * * * *', klass: 'PriceWorker')

And this is the answer

=> #<Sidekiq::Cron::Job:0x000055b6d54707e8
@active_job=false,
@active_job_queue_name_delimiter=nil,
@active_job_queue_name_prefix=nil,
@args=[],
@cron="*/2 * * * *",
@fetch_missing_args=true,
@klass="PriceWorker",
@last_enqueue_time=nil,
@message={"retry"=>false, "queue"=>"default", "class"=>"PriceWorker",   "args"=>[]},
@name="TestWorker_Job",
@queue="default",
@queue_name_with_prefix="default",
@status="enabled">

But it throws me an error:

job.errors
=> ["'cron' -> */2 * * * *: uninitialized constant Rufus::Scheduler::CronLine"]

There is no valid job. I don't know what i am doing wrong. Sidekiq-cron github page do the same thing.

jmettraux
  • 3,511
  • 3
  • 31
  • 30
  • Before posting here, please check the project's issue tracker. You'll find answers at https://github.com/ondrejbartas/sidekiq-cron/issues/199 – jmettraux Jun 01 '18 at 02:39

1 Answers1

8

sidekiq-cron is not targeting the correct version of rufus-scheduler. To make it work again, add this to your Gemfile:

gem 'rufus-scheduler', '~> 3.4.0'

Then run $ bundle install rufus-scheduler.

Esben Damgaard
  • 309
  • 1
  • 10
  • 2
    Rufus-scheduler is using semantic versioning. Sidekiq-cron was using a "behind the scene" rufus-scheduler feature that changed in the newer versions. Also sidekiq-cron was depending on rufus-scheduler ">= 3.3.0" instead of the classical "~> 3.3", it was bound for such an issue. Rufus-scheduler has not to be compatible to a downstream project, it's the other way around. – jmettraux Sep 20 '18 at 09:06
  • 1
    Thanks for the clarification. I changed the text. Please change your downvote, as the solution does work. – Esben Damgaard Sep 21 '18 at 07:20
  • Done. Thanks a lot! – jmettraux Sep 21 '18 at 15:37