简体   繁体   中英

Cron job doesn't run 'runner' task that uses Sidekiq

I generated a Cront Job using the Whenever gem

every 15.minutes do
    command "date >> ~/cron.txt"
    runner "Location.update_days"
end

By typing crontab -l in the command line I get:

0,15,30,45 * * * * /bin/bash -l -c 'date >> ~/cron.txt'

0,15,30,45 * * * * /bin/bash -l -c 'cd /opt/www/my_app && bin/rails runner -e production '\''Location.update_days'\'''

Apparently the command tasks work just fine and I do get the date printed to cron.txt every 15 minutes but the runner task doesn't run.

The Location.update_days calls a Sidekiq worker to perform a task and it works when run from the rails console but not when it is called by cron.

def self.update_days
   new_day = self.new_day

   self.where( current_location: true,
            self.season => new_day[:timezone]
          ).find_each do |location|
            day = location.days.create new_day
            SidekiqWorker.perform_async day.id
          end
end

Do you have any idea what might be wrong or how can I debug this problem?

I know that you said it ran from the console fine, but did you try running the bash script that the cron job runs to see if there were obvious errors? It's possible that the cron job fails before the Ruby class is even loaded.

/bin/bash -l -c 'cd /opt/www/my_app && bin/rails runner -e production '\''Location.update_days'\'''

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM