Whenever Sidekiq does not start

I am trying to configure Sidekiq Scheduler to run recurring jobs.

I can get the Sidekiq task to work in the Rails or Rails console. I can get when to run the command. However, I CAN'T get it every time you start Sidekiq working.

I have reproduced my work on different machines and I got it working on some machine. It doesn't work in most other machines.

Here's my setup:

# app/workers/create_random_product.rb
class CreateRandomProduct
  include Sidekiq::Worker

  def perform
    new_product = Product.new
    new_product.name = "Product #{Time.now}"
    new_product.price = 5.5
    new_product.save
  end
end

# config/schedule.rb
every 1.minute do
  runner "CreateRandomProduct.perform_async"
  command "echo 'hello' >> /home/vagrant/output.txt"
end

      

As you can see in sched.rb, I can run the second command because I can see the result is updated, but the first runner command does nothing. The Sidekiq dashboard also shows no activity.

Executing "whenever" returns these cron jobs:

* * * * * /bin/bash -l -c 'cd /home/vagrant/sidekiqdemo && bin/rails runner -e production '\''CreateRandomProduct.perform_async'\'''

* * * * * /bin/bash -l -c 'echo '\''hello'\'' >> /home/vagrant/output.txt'

      

I ran the first command manually and it gets Sidekiq running.

I ran the command "someday" to update the crontab file. I check the crontab log and see that it was trying to get Sidekiq running:

Oct 16 16:15:01 vagrant-ubuntu-trusty-64 CRON[13062]: (vagrant) CMD (/bin/bash -l -c 'cd /home/vagrant/sidekiqdemo && bin/rails runner -e production '\''CreateRandomProduct.perform_async'\''')
Oct 16 16:15:01 vagrant-ubuntu-trusty-64 CRON[13063]: (vagrant) CMD (/bin/bash -l -c 'echo '\''hello'\'' >> /home/vagrant/output.txt')

      

Is there something I am missing?

+3


source to share


1 answer


I decided to define it new job_type

as suggested here . For this to work, you need to install sidekiq-client-cli .

In addition, I discovered thanks to this a message that when a command is executed from the cron process, only a set of environment variables are set in such a way that in my case the command did not work because mine was BUNDLE_PATH

not set. at the end my worker job_type

looks something like this:

job_type :sidekiq, "cd :path && BUNDLE_PATH=/bundle /usr/local/bin/bundle exec sidekiq-client :task :output"

every 1.minute do
  sidekiq "push GenerateExportsWorker"
end

      



that's why in my case a command like

every 1.minute do
  command "echo 'you can use raw cron syntax too' >> /home/log/myscript.log 2>&1 "
end

      

despite the other.

0


source







All Articles