Im trying to setup whenever gem in my Ubuntu 14.04 server. In my local machine it works fine. I use capistrano to deploy the site. I use rbenv in the server. But when installing passenger it installs Ruby 1.9 which I do not use. Only use rbenv. Here's my shcedule.rb :
set :output, "#{path}/log/cron.log"
every 30.minutes do
runner 'UploadmailWorker.perform_async'
end
every 12.hours do
runner 'SubscriptionWorker.perform_async'
end
every :month do
runner 'PaysellerWorker.perform_async'
end
My deploy.rb :
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
set :whenever_roles, ->{ :app }
set :whenever_command, ->{ [:bundle, :exec, :whenever] }
set :whenever_command_environment_variables, ->{ {} }
set :whenever_identifier, ->{ fetch :application }
set :whenever_environment, ->{ fetch :rails_env, fetch(:stage, "production") }
set :whenever_variables, ->{ "environment=#{fetch :whenever_environment}" }
set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }
set :whenever_clear_flags, ->{ "--clear-crontab #{fetch :whenever_identifier}" }
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
After deploying, the whenever does not work. In the cron.log I find this error :
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/deploy/istockseller/releases/20150519112817/config/boot.rb:3:in `<top (required)>'
from bin/rails:7:in `require_relative'
from bin/rails:7:in `<main>'
How can I fix that?
Same problem here
@THPubs I was able to fix it by inserting:
env :PATH, ENV['PATH']
At the beginning of my schedule.rb file
I've had the same problem of you guys and the solution is to fix the setup of capistrano so you have to remove bin from the linked dir and put binstubs to nil in order to make it working. I've been struggling for hours on that.
But if you still can't make it working properly I would suggest to use my free service to outsource the cronjobs, you create an endpoint on you app and make http GET or POST request as often as you need with http://guardiano.getpeople.in
For some of my prototype or when I don't want to struggle with cronjobs I'm using this (that is why I created it and made public) and is working fine. Hope this helps!
I am facing same issue on production. @jpmermoz the solution you suggested doesn't work either.
I figured it out. See details http://stackoverflow.com/questions/32293583/error-running-cron-job-require-cannot-load-such-file-bundler-setup-loader
Same problem here.The answer is here http://stackoverflow.com/questions/32293583/error-running-cron-job-require-cannot-load-such-file-bundler-setup-loader
Some problem, solved with @zongyannan and @AmitPatel-BoTreeConsulting tips. But if you are using rbenv, should do this:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Thank's
Most helpful comment
Some problem, solved with @zongyannan and @AmitPatel-BoTreeConsulting tips. But if you are using rbenv, should do this:
Thank's