In my rails application, i want to run model function using whenever gem. My schedule.rb file like,
set :environment, 'development'
set :output, "#{path}/log/cron.log"
set :job_template, "bash -l -c ':job'"
job_type :runner, "cd :path && bin/rails runner -e :environment ':task' :output"
every 2.minutes do
runner "Book.jobrun"
end
every 2.minutes do
command "echo 'rink4'"
end
And book.rb model like,
self.jobrun
Rails.logger.info "cronjob is running"
end
But when i run cronjob, in cron.log file showing,
bin/rails:3: undefined method `require_relative' for main:Object (NoMethodError)
How i need to set ruby path or rails path?
Try running which ruby
from cron. Is it as you expect? If not, cron is likly defaulting to system Ruby which in your case is probably version 1.8.7 and doesn't have the require_relative
function.
Check which ruby executble you're using with which ruby
. And use this in the shebang at the top of your bin/rails. for instance
bin/rails
#!/Users/<username>/.rvm/rubies/ruby-2.2.4/bin/ruby.
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.