I am using whenever gem to write a simple cron job like.
every 1.minute do
runner "ValidModel.clean"
end
I see that this cron fires at the right time but the rails command ValidModel.clean doesn't succeed. It gives the following error.
/home/deploy/.rvm/rubies/ruby-2.4.2/lib/ruby/site_ruby/2.4.0/rubygems.rb:271:in `find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
from /home/deploy/.rvm/rubies/ruby-2.4.2/lib/ruby/site_ruby/2.4.0/rubygems.rb:299:in `activate_bin_path'
from /home/deploy/.rvm/gems/ruby-2.4.2/bin/bundle:23:in `<main>'
from /home/deploy/.rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:15:in `eval'
from /home/deploy/.rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:15:in `<main>'
I am using RVM. Is this issue related with using RVM with whenever? I appreciate any help!
UPDATE:
In gemfile i have put
gem 'whenever', require: false
when i run crontab -l it lists the following
PATH=/home/deploy/apps/app/shared/bundle/ruby/2.4.0/bin:/home/deploy/.rvm/gems/ruby-2.4.2/bin:/home/deploy/.rvm/gems/ruby-2.4.2#global/bin:/home/deploy/.rvm/rubies/ruby-2.4.2/bin:/home/deploy/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
GEM_PATH=""
* * * * * /bin/bash -l -c 'cd /home/deploy/apps/app/releases/20180121061036 && bundle exec bin/rails runner -e production '\''ValidModel.clean'\'' >> /home/deploy/apps/app/releases/20180121061036/log/cron.log 2>&1'
I appreciate any insights! Thanks a lot!
Related
I'm getting this one error I don't understand (I'm fairly new to rails) when using the gem 'whenever' in development mode.
What I did was update config/schedule.rb and run
whenever --update-crontab --set environment='development'
crontab -l lists:
* * * * * /bin/bash -l -c 'cd /home/vic/Desktop/WorkflowProject && bundle exec bin/rails runner -e development '\''Task.new2'\'' >> log/whenever.log 2>&1'
at config/schedule.rb
set :output, 'log/whenever.log'
every 1.minute do
runner "Task.new2"
end
at log/whenever.log
bundler: failed to load command: bin/rails (bin/rails)
Bundler::GemNotFound: Your bundle is locked to rake (11.3.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of rake (11.3.0) has removed it. You'll need to update your bundle to a different version of rake (11.3.0) that hasn't been removed in order to install.
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:179:in `rescue in specs'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:173:in `specs'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:233:in `specs_for'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:222:in `requested_specs'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/runtime.rb:118:in `block in definition_method'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/runtime.rb:19:in `setup'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler.rb:99:in `setup'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/setup.rb:20:in `<top (required)>'
/home/vic/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/vic/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I would grealy appreciate the help, thank you very much!
Try the below commands.
gem install rubygems-bundler
gem regenerate_binstubs
Ref: this
Are you sure to have bundler installed? Try running bundle install inside your application directory.
If no, see Jayaprakash's answer above.
If yes, try bundle exec whenever --update-crontab --set environment='development'.
Update:
Ahh, missed that you are seeing error when your task executes.
Try this in your config/schedule.rb
env :PATH, ENV['PATH']
set :output, "#{ Whenever.path }/log/whenever.log"
every 1.minute do
runner "Task.new2"
end
When running rake commands, I get this error:
You have already activated rake 10.0.2, but your Gemfile requires rake 11.1.1.
Prepending `bundle exec` to your command may solve this.
How do I fix this so that I don't have to run bundle exec before every rake command?
I uninstalled rake and reinstalled, but it's still looking for an older version:
C:/Ruby22-x64/bin/rake:22:in `load': cannot load such file -- C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-10.4.2/bin/rake (LoadError)
from C:/Ruby22-x64/bin/rake:22:in `<main>'
run
$ bundle update rake
that worked for me.
see the documentation.
http://bundler.io/v1.3/man/bundle-update.1.html
Pretty simple:
gem install rake -v 11.1.1
For me it was just that I needed to use sudo bundle exec rake <...>, maybe it can help someone else...
(I was trying to install concerto on a RaspberryPi, FYI)
UPDATE:
gem 'rake','10.0.2' in gemfile
gem uninstall rake
remove gemfile.lock
bundle update rake
Simply remove your gemfile.lock and do bundle install :)
simply write this
gem install rake
Check your Gemfile.lock for rake version, you should find something like
rake (10.0.2)
If you found the above then you have to remove your gemfile.lock then run bundle install again.
And it wouldnt hurt to double check that you are on the right project.
just write a command starting with bundle exec example bundle exec rake db:schema
The problem is your installed rake has a different version to the rake in your Gemfile.lock. Just go in there, Cmd + F to search for 'rake', change the version number to the one that terminal wants.
The problem is the rake version you are using is not same as that in your Gemfile, you must make sure of that there's no difference, you can also take no more bundle exec ... with rubygems-bundler
gem install rubygems-bundler
next run (once)
gem regenerate_binstubs
I have deployed application using Capistrano 3. I keep on getting following error.
`require': cannot load such file -- bundler/setup (LoadError)
Here is the cron tab list
PATH=/home/deploy/magnificent/shared/bundle/ruby/2.2.0/bin:/usr/local/rvm/gems/ruby-2.2.2/bin:/usr/local/rvm/gems/ruby-2.2.2#global/bin:/usr/local/rvm/rubies/ruby-2.2.2/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
* * * * * /bin/bash -l -c 'cd /home/deploy/magnificent/releases/20150830045359 && bin/rails runner -e production '\''Document.process_pending'\'' >> log/cron_standard.log 2>> log/cron_error.log'
and schedule.rb
env :PATH, ENV['PATH']
set :output, { error: 'log/cron_error.log', standard: 'log/cron_standard.log'}
every 1.minutes do
runner 'Document.process_pending'
end
Please note here that all the gems are installed in default gemset
Please note here that all the gems are installed in default gemset
I had 3 gemsets available in production. Rails is using default one where all required gems are installed.
As can be seen in the crontab list, crontab is also looking path in global gemset directory as well.
So I just selected global gemset and install bundler
$ rvm gemset use global
$ gem install bundler
These steps fixed the issue.
This worked for me:
rvm cron setup
In my Rails 3.2 app I have a custom rake task that I am trying to run every day at 5pm with a cron job. Right now I am running it on our site's Staging server. The cron job is setup correctly but according to the e-mail output from the cron daemon the rake is being aborted because it's trying to invoke sqlite3.
Here is my cron job:
#crontab
0 17 * * * cd /u/apps/my_app/current && /usr/local/bin/rake my_task
I have reserved sqlite3 for development and test, like so:
#Gemfile
group :development, :test do
gem 'factory_girl_rails'
gem 'letter_opener'
gem 'rspec-rails'
gem 'sqlite3'
gem 'thin'
gem 'pry-rails'
end
I also have set my rake task to load the proper environment like so:
#mytask.rake
task :my_task => :environment do
# my task
end
This is the error I'm getting in the e-mail from crond:
rake aborted!
Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (sqlite3 is not part of the bundle. Add it to Gemfile.)
If I run the rake tasks directly from the shell I don't get an error. It would seem that this works because of the following line in ~/.bashrc:
alias rake='RAILS_ENV=staging rake'
This, however, doesn't seem to have any effect on the task when run from the cron job. I've tried adding export RAILS_ENV=staging to the .bashrc file as recommended here but it didn't help.
The one thing I've found that works is writing the cron job like this:
#crontab
0 17 * * * cd /u/apps/my_app/current && /usr/local/bin/rake my_task RAILS_ENV=staging
...with the env declaration directly in the cron command. This doesn't seem very elegant but it's okay for now. Is there a better way to go about this?
Υou can set the environment variables in crontab (not in Arch or RedHat though...)
try setting your crontab as follows
#crontab
RAILS_ENV=staging
0 17 * * * cd /u/apps/my_app/current && /usr/local/bin/rake my_task
I'm having problems running my rake task from cron, I wrap it in shell file and when I execute this shell file from console it works fine.
#!/bin/sh
if ps -ef | grep -v grep | grep create_all_accounts ; then
exit 0
else
cd /home/prosoftstudio/www/prosoftstudio_egabinet && /home/prosoftstudio/www/.ruby/gems/1.8/bin/rake gabinet:create_all_accounts RAILS_ENV=production --trace
exit 0
fi
Entry in crontab looks like this(I set PATH and GEM_PATH)
PATH=/home/prosoftstudio/www/.python/bin:/usr/local/python2.6/bin:/home/prosoftstudio/www/.ruby/gems/1.8/bin/:/usr/local/ruby1.8/bin:/usr/local/bin:/usr/bin:/bin:/us$
GEM_PATH=/home/prosoftstudio/www/.ruby/gems/1.8:/home/prosoftstudio/www/.ruby/gems/1.8/bundler/gems:/usr/lib/ruby/gems/1.8/
*/1 * * * * /home/prosoftstudio/www/cron_create_accounts.sh > cron_log.txt 2>&1
The output I get is
rake aborted!
git://github.com/100hz/rails-settings.git (at master) is not checked out. Please run `bundle install`
It seems like it can't find gems installed with
gem "rails-settings", :git => "git://github.com/100hz/rails-settings.git"
Anyone know how to fix this?
I came up with workaround - installing rails-settings from source
wget https://github.com/100hz/rails-settings/zipball/master --no-check-certificate
unzip 100hz-rails-settings-v0.1.1-0-g330b958.zip
cd 100hz-rails-settings-330b958/
gem build rails-settings.gemspec
gem install rails-settings-0.1.1.gem
and you have to remove ":git =>" from gem "rails-settings" in Gemfile, and run
bundle install
to update Gemfile.lock
After that my script run from cron.
To avoid building a gem, another option is to put the gem content in the vendor folder and reference it through :path in Gemfile:
gem "my_gem", :path => "vendor/my_gem"