whenever is a Ruby on Rails gem and is often used when setting up crontab.
The usage is described in detail on the Github homepage, but the main ones are as follows.
** Add to Gemfile **
Gemfile
gem 'whenever', require: false
** Install **
bundle exec wheneverize .
** Check the contents of the schedule.rb file **
whenever
** Update crontab in development environment **
whenever --update-crontab --set environment='development'
config/deploy.rb
set :whenever_roles, -> { :app }
Capfile
require 'whenever/capistrano'
After deploying to EC2, crontab does not work, and when I check the log, the Bundle version is incorrect.
Job_type should be set to
config/schedule.rb
set :output, environment == 'development' ? 'log/crontab.log' : '/deploy/apps/<app name/shared/log/crontab.log'
job_type :rake, 'export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; cd :path && RAILS_ENV=:environment bundle exec rake :task :output'
The time zone is likely to be wrong.
How to set the time zone:
config/schedule.rb
require 'active_support/core_ext/time'
def local(time)
Time.zone = 'Asia/Tokyo'
Time.zone.parse(time).localtime($system_utc_offset)
end
every 1.day, at: local('6:00 am') do #Runs every morning at 6am Japan time
rake '<task>'
end
Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
Just add mini_racer
to your Gemfile. therubyracer
is fine, but it's difficult to install on Mac, so use mini_racer
.
Recommended Posts