Cron job not working in Whenever gem
Finally I have solved how to run the gem Whenever.
It's working good on production, but not in development mode (I think that to working good in dev mode you must do some tricks).
Then, these are the processes to do:
- install the gem
- write your
scheduler.rb
file - push to the remote server
- login to the remote server (for example with
ssh
) - see if whenever is good uploaded by running in terminal:
whenever
- update whenever crontab by running:
whenever --update-crontab
- restart the server crontab (for example in Ubuntu server):
sudo service cron restart
- check if crontab is good implemented on the server:
crontab -l
That's it!
Personally, I prefer to set up my crons directly from the server:
- Edit the crontab:
crontab -e
- Append my cron (e.g. every day at 5:00 AM - can be little different for not-Linux-based server):
0 5 * * * /bin/bash -l -c 'cd /path_to_my_app/current && RAILS_ENV=production bundle exec rake my_cron_rake'
- Check if good implemented:
crontab -l
- Done
Rails whenever gem not working
whenever
actually does not automatically run that job for you. It is just an easy way for you to create corresponding cronjob on your system. You need to run the following command on your project to update your crontab
whenever -i
Regards
Rails 5: Cron jobs using Whenever not running
In your schedule.rb file, your environment is set to development and in the response of crontab -l command the environment is set to production,
You can set the environment like this,
set :environment, "development"
set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}
every 1.minute do
rake "check_price:check_now"
end
Rails Whenever gem not executing repetitive crontab task with Ubuntu and Docker Compose
- you can run
cron
to start cron service (linux) in yourentrypoint.sh
# Update crontab file using whenever command.
cron && bundle exec whenever --set 'environment=production' --update-crontab
- schedule don't know the gems path so the
Bundler::GemNotFound
error be throw, to solve this, you can avoid missing paths by setting all ENV inschedule.rb
set :output, "log/cron_log.log"
ENV.each { |k, v| env(k, v) }
# ...
Related Topics
Iterate Through Every File in One Directory
Difference Between Print and Puts
How to Install Therubyracer Gem on 10.10 Yosemite
Rails Paperclip How to Delete Attachment
Haml: Append Class If Condition Is True in Haml
Extract a Substring from a String in Ruby Using a Regular Expression
How to Get Rid of Non-Ascii Characters in Ruby
Confusion With Atomic Grouping - How It Differs from the Grouping in Regular Expression of Ruby
Converting String from Snake_Case to Camelcase in Ruby
When to Use Each Method of Launching a Subprocess in Ruby
Nomethoderror When Trying to Invoke Helper Method from Rails Controller
How Do Rvm and Rbenv Actually Work
Ruby: How to Turn a Hash into Http Parameters
Create a Devise User from Ruby Console