whenever is a gem that help you write cron job on server more easy, Github:

Code here

this work on my ubuntu server, I have tested
file path: config/schedule.rb

set :path, "/var/www/yuzhu/current"
set :bundle_path, "/usr/local/bin/bundle"
set :rails_path, "/usr/local/bin/rails"
set :output, {:error => "/var/www/random_log/cron_error_log.log", :standard => "/var/www/random_log/cron_log.log"}

job_type :my_rails, 'cd :path && :bundle_path exec :rails_path runner -e production :task :output'

every 3.hours do
  my_rails "Location.cal_score"
  my_rails "Location.cal_price"

Sorry, this blog called "Ghost". they don't have code highlight yet.

set :path is because I am using Capistranorb to deploy,
if I don't write this, the path would become /var/www/yuzhu/releases/20171102091713

set :bundle_path and set :rails_path is because when I debug using set :output and following code

every 1.minute do
  runner "Location.cal_score"
  runner "Location.cal_price"

it just keep saying can't find bundle & can't find rails command.

env PATH not working too (If you have searched on Google, I believe you already saw following solution)

env :PATH, ENV['PATH']
set :environment, ENV['RAILS_ENV']

that's why I use set :bundle_path and set :rails_path


I spend entire afternoon on this!!!

I hope this can save your time.