* * * * * /bin/bash -l -c 'cd /Users/boris/projects/MyApp/ && rails runner "Resque.enqueue(Place)"'
Basically I need to do the following:
Load Ruby with RVM
Navigate to MyApp Dir
Run the following line: rails runner "Resque.enqueue(Place)
The above cron seems to be running, but its producing the following errors with rails runner
whats going on?
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/dependency.rb:52:in `initialize': Valid types are [:development, :runtime], not nil (ArgumentError)
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:359:in `new'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:359:in `search'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:354:in `gems_size'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:179:in `resolve'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/source_index.rb:95:in `sort_by'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:175:in `each'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:175:in `sort_by'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:175:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:160:in `start'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:128:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:127:in `catch'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/resolver.rb:127:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:151:in `resolve'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:90:in `specs'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:135:in `specs_for'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/definition.rb:124:in `requested_specs'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/environment.rb:23:in `requested_specs'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:11:in `setup'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler.rb:107:in `setup'
from /Users/boris/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/setup.rb:6
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /Users/boris/projects/chaggregator/config/boot.rb:6
from script/rails:5:in `require'
from script/rails:5
Actually the best way to do this is to use rvm wrapper. You can create a wrapper like this:
rvm wrapper ruby-1.9.3-p0#somegemset appname rails
binary can be rails, rake, gem or whatever other ruby binary you have installed. What happens is that rvm creates a wrapper that will source the correct rvm environment before executing the rails command. On system wide rvm, the wrapper will normally be placed in /usr/local/rvm/bin/
Now from cron you can just do:
*/3 * * * * cd /path/to/your/app && appname_rails runner "Resque.enqueue(Place)" -e production
This will cd into your app directory and execute the rvm wrapper you just created every 3 minutes. This example is based on rails 3 and production environment.
You need to source the right environment via RVM before any Ruby code runs. So include something like this in the command:
source /usr/local/rvm/environments/ruby-1.9.2-p180#my-gemset
So a potential solution would be:
SHELL=/bin/bash
* * * * * source /{path_to_rvm_environment_for_ruby}#{gemset} && cd /Users/boris/projects/MyApp/ && rails runner "Resque.enqueue(Place)"'
Lots of moving pieces here, here are a couple of pointers on things to check in your environment (ruby, rvm, bundle) - post your findings and will go from there.
Path's issue with bundler, to change or not to change?
Bundle bug
I guess the commands runs fine outside of cron? if you're running your cron job as a different user, check the environment of that user.
Related
I used to debug test cases in ruby mine for my rails test cases. Some time ago I updated my ruby mine and not sure what happened since then, I am not able to debug my test cases.
Attaching the screenshot of the error below:
What can be done here to rectify this?
Here is the same console output in plain text:
Testing started at 12:53 PM ...
bash -c "/Users/someUSER/.rvm/bin/rvm ruby-2.3.1 do /Users/someUSER/.rvm/rubies/ruby-2.3.1/bin/ruby /Users/someUSER/.rvm/gems/ruby-2.3.1#global/gems/ruby-debug-ide-0.7.0.beta6/bin/rdebug-ide --key-value --disable-int-handler --evaluation-timeout 10 --evaluation-control --time-limit 100 --memory-limit 0 --rubymine-protocol-extensions --port 49496 --host 0.0.0.0 --dispatcher-port 49497 -- /Users/someUSER/.rvm/gems/ruby-2.3.1/bin/rspec /Users/someUSER/RubymineProjects/Proj/spec/controllers/site/some_controller_spec.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter --example \"Site::SomeController Some POST create new data \""
Fast Debugger (ruby-debug-ide 0.7.0.beta6, debase 0.2.2, file filtering is supported) listens on 0.0.0.0:49496
Uncaught exception: cannot load such file -- rspec/core/formatters/fallback_message_formatter
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/formatters.rb:132:in `require'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/formatters.rb:132:in `setup_default'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:47:in `block in prepare_default'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:228:in `ensure_listeners_ready'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:199:in `notify'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:92:in `message'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:161:in `notify_non_example_exception'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:2037:in `rescue in load_file_handling_errors'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:2034:in `load_file_handling_errors'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1560:in `block in load_spec_files'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1558:in `each'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1558:in `load_spec_files'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:98:in `setup'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:86:in `run'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:71:in `run'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:45:in `invoke'
/Users/someUSER/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/exe/rspec:4:in `<top (required)>'
/Users/someUSER/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `load'
/Users/someUSER/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `<top (required)>'
/Users/someUSER/.rvm/gems/ruby-2.3.1#global/gems/ruby-debug-ide-0.7.0.beta6/bin/rdebug-ide:187:in `<main>'
Process finished with exit code 1
Empty test suite.
I think you are having problems to install the debug gem for RubyMine. I had the same issue and after taking a look at JetBrains web page seems like they are working to fix it on RubyMine 2018.3.3. Meantime, a workaround is to install the gems in a console.
Open the terminal inside RubyMine and run:
gem install debase -v 0.2.3.beta3 --no-document
gem install ruby-debug-ide -v 0.7.0.beta7 --no-document
The beta6 version of the ruby-debug-ide gem that you use is older than rspec 3.8. Maybe upgrading ruby-debug-ide to the latest beta7 version helps (or downgrading rspec to a version older than beta6).
I followed this issue https://github.com/javan/whenever/issues/714
and set my schedule.rb like this.
env :PATH, ENV['PATH']
set :output, {:error => '~/Desktop/z.error.log', :standard => '~/Desktop/z.standard.log'}
every 1.minute do
runner 'Price.create'
end
Then I check my crontab -l, it showed the following command
PATH=/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails514/bin:/Users/MyUserName/.rvm/gems/ruby-2.3.3#global/bin:/Users/MyUserName/.rvm/rubies/ruby-2.3.3/bin:/Users/MyUserName/.rvm/bin:/usr/local/opt/mysql#5.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
* * * * * /bin/bash -l -c 'cd /Users/MyUserName/Desktop/my-project && bundle exec bin/rails runner -e production '\''Price.create'\'' >> ~/Desktop/z.standard.log 2>> ~/Desktop/z.error.log'
# End Whenever generated tasks for: /Users/MyUserName/Desktop/my-project/config/schedule.rb at: 2018-01-30 02:13:32 +0800
It seems great and executable, however, I checked the error log and found the following errors.
bundler: failed to load command: bin/rails (bin/rails)
Bundler::GemNotFound: Could not find erubi-1.7.0 in any of the sources
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/spec_set.rb:88:in `block in materialize'
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/spec_set.rb:82:in `map!'
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/spec_set.rb:82:in `materialize'
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/definition.rb:170:in `specs'
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/definition.rb:237:in `specs_for'
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/definition.rb:226:in `requested_specs'
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/runtime.rb:108:in `block in definition_method'
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/runtime.rb:20:in `setup'
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler.rb:107:in `setup'
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/setup.rb:20:in `<top (required)>'
/Users/MyUserName/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/Users/MyUserName/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I felt a little bit confused and wondering why I could not load the right gem path.
Environment:
OSX: 10.13.2
Rails 5.1.4
Ruby 2.3.3
Update
I found out that the error message from log stated that
/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails4271/gems/bundler-1.16.1/lib/bundler/spec_set.rb:88:in `block in materialize'`,
However, I check my crontab -l, it clearly showed this setting
#sm start rvm
PATH="/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails514/bin:/Users/MyUserName/.rvm/gems/ruby-2.3.3#global/bin:/Users/MyUserName/.rvm/rubies/ruby-2.3.3/bin:/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails514/bin:/Users/MyUserName/.rvm/gems/ruby-2.3.3#global/bin:/Users/MyUserName/.rvm/rubies/ruby-2.3.3/bin:/Users/MyUserName/.rvm/bin:/usr/local/opt/mysql#5.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin"
GEM_HOME='/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails514'
GEM_PATH='/Users/MyUserName/.rvm/gems/ruby-2.3.3#rails514:/Users/MyUserName/.rvm/gems/ruby-2.3.3#global'
MY_RUBY_HOME='/Users/MyUserName/.rvm/rubies/ruby-2.3.3'
IRBRC='/Users/MyUserName/.rvm/rubies/ruby-2.3.3/.irbrc'
RUBY_VERSION='ruby-2.3.3'
#sm end rvm
I am confused why it still get the wrong rvm version.
Did I miss something?
Update 2
After I changed the default gemset, it works perfectly.
I used this command
rvm use 2.3.3#rails514 --default
But does anyone can tell me how to put the right path in crontab instead of setting rvm default?
Try to run
rvm cron setup
Not sure if it fix the problem, but had a similar issue once, and worked for me. Good luck!
Operating System: Ubuntu installed on a docker and a normal ubuntu installed on my personal laptop.
I am running this cron job:
*/5 * * * * /bin/bash -l -c "cd /home/deploy/railsapp && rake spec >> cron.log 2>&1"
I have tried it with bundle exec rake spec, without /bin/bash, with whenever gem, with /usr/local/bin/rake spec, but still nothing is happening except these errors.
Errors in the log file on running the cron job:
/bin/bash: bundle: command not found
/bin/bash: rake: command not found
rake aborted!
Bundler::GemNotFound: Could not find rake-11.2.2 in any of the sources
/home/deploy/railsapp/config/boot.rb:3:in `<top (required)>'
/home/deploy/railsapp/config/application.rb:1:in `<top (required)>'
/home/deploy/railsapp/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/home/deploy/railsapp/config/boot.rb:3:in `<top (required)>'
/home/deploy/railsapp/config/application.rb:1:in `<top (required)>'
/home/deploy/railsapp/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
bundler: failed to load command: rake (/usr/local/bin/rake)
Bundler::GemNotFound: Could not find rake-11.2.2 in any of the sources
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:95:in `block in materialize'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `map!'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `materialize'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:185:in `specs_for'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:174:in `requested_specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/environment.rb:19:in `requested_specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:14:in `setup'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:95:in `setup'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/setup.rb:19:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
On running rake spec manually from the command line its working fine, but from cron it is giving this error.
Any ideas ?
I am pretty sure that the issue is caused by not correctly set environment. Basically cron runs with the minimal environment so it is not aware about settings from for example .bashrc file (where you have rvm or rbenv initialization and PATH settings).
Source your environment file using . so rewrite the cron entry to something like:
*/5 * * * * /bin/bash -l -c ". /etc/environment && cd /home/deploy/railsapp && rake spec >> cron.log 2>&1"
Note that /etc/environment is just an example. You can source files like .bashrc instead.
I use whenever gem to manage crontab.
Adding
ENV.each { |k, v| env(k, v) }
to the config/schedule.rb file solved this issue for me.
Reference: https://github.com/javan/whenever/issues/656#issuecomment-239111064
Use whenever gem - this is adapter for cron, with support of rake tasks and other ruby/rails things.
I am getting the following error whenever I type any command on all my rails applications. I working on a virtual machine in cloud 9. Any idea or guidance?
(master) $ bundle exec rspec spec/
/opt/rh/ruby193/root/usr/share/rubygems/rubygems/specification.rb:541:in `read': Permission denied - /usr/libexec/openshift/cartridges/c9-0.1/root/lib/ruby/gems/specifications/multi_json-1.8.4.gemspec (Errno::EACCES)
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/specification.rb:541:in `load'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/specification.rb:269:in `block (2 levels) in _all'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/specification.rb:268:in `each'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/specification.rb:268:in `block in _all'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/specification.rb:267:in `each'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/specification.rb:267:in `_all'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/specification.rb:410:in `each'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/dependency.rb:216:in `find_all'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/dependency.rb:216:in `matching_specs'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/dependency.rb:238:in `to_specs'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/dependency.rb:256:in `to_spec'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems.rb:1231:in `gem'
from /usr/libexec/openshift/cartridges/c9-0.1/root/lib/ruby/gems/bin/bundle:22:in `<main>'
It sounds like your gems were installed with sudo access, which your current user (web runner?) lack the right perms to see the Ruby install dir.
I can't quite say why the gems were installed to a path like /usr/libexec/openshift/cartridges — perhaps this is part of your cloud host's setup?
Do you boot your own rails server out of your instance? e.g. like you installed Unicorn, nginx, etc. on your own? If so, you can use rbenv to install a ruby and gemset to a local path over which you have full permission control.
If you don't have scenario #1 above, then the setup may be misconfigured by the host, and you should open a ticket.
I recently ran into a problem and in desperation decided to uninstall and reinstall both Ruby and Rails on my OS X 10.6. I've reinstalled Ruby and gem installed rails. Now, though, I get this error or similar EVERY time I try to run a rails command (even -v):
rails -v
/Users/Dylan/.rvm/gems/ruby-1.9.3-p125#global/gems/bundler-1.1.5/lib/bundler/spec_set.rb:90:in `block in materialize': Could not find bcrypt-ruby-3.0.1 in any of the sources (Bundler::GemNotFound)
from /Users/Dylan/.rvm/gems/ruby-1.9.3-p125#global/gems/bundler-1.1.5/lib/bundler/spec_set.rb:83:in `map!'
from /Users/Dylan/.rvm/gems/ruby-1.9.3-p125#global/gems/bundler-1.1.5/lib/bundler/spec_set.rb:83:in `materialize'
from /Users/Dylan/.rvm/gems/ruby-1.9.3-p125#global/gems/bundler-1.1.5/lib/bundler/definition.rb:127:in `specs'
from /Users/Dylan/.rvm/gems/ruby-1.9.3-p1
25#global/gems/bundler-1.1.5/lib/bundler/environment.rb:27:in `specs'
from /Users/Dylan/.rvm/gems/ruby-1.9.3-p125#global/gems/rubygems-bundler-1.0.3/lib/rubygems-bundler/noexec.rb:41:in `candidate?'
from /Users/Dylan/.rvm/gems/ruby-1.9.3-p125#global/gems/rubygems-bundler-1.0.3/lib/rubygems-bundler/noexec.rb:60:in `setup'
from /Users/Dylan/.rvm/gems/ruby-1.9.3-p125#global/gems/rubygems-bundler-1.0.3/lib/rubygems-bundler/noexec.rb:75:in `<top (required)>'
from /Users/Dylan/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /Users/Dylan/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /Users/Dylan/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Users/Dylan/.rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:9:in `<main>'
ANy ideas on how to fix this?
It seems like you need to install bcrypt-ruby
Maybe try sudo gem install bcrypt-ruby?
Run bundle install then run bundle exec rails -v see if this clears the issue.