Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i set ruby version in cron job? #325

Closed
bolasblack opened this issue Mar 24, 2013 · 5 comments
Closed

How can i set ruby version in cron job? #325

bolasblack opened this issue Mar 24, 2013 · 5 comments

Comments

@bolasblack
Copy link

My schedule.rb :

set :output, 'log/cron.log'
set :job_template, "/bin/bash -c \":job\""
set :environment, :development
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"

every 1.minute do
  runner "Entry.storage_new_entries"
end

Then whenever generated cron job:

* * * * * /bin/bash -c "cd /Users/c4605/workSpace/read && script/rails runner -e development 'Entry.storage_new_entries' >> log/cron.log 2>&1"

It work when it executed by my self, but log/cron.log said:

/Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler/spec_set.rb:92:in `materialize': Could not find rake-10.0.2 in any of the sources (Bundler::GemNotFound)
        from /Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler/spec_set.rb:85:in `map!'
        from /Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler/spec_set.rb:85:in `materialize'
        from /Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler/definition.rb:114:in `specs'
        from /Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler/definition.rb:159:in `specs_for'
        from /Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler/definition.rb:148:in `requested_specs'
        from /Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler/environment.rb:18:in `requested_specs'
        from /Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler/runtime.rb:13:in `setup'
        from /Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler.rb:120:in `setup'
        from /Library/Ruby/Gems/1.8/gems/bundler-1.3.0/lib/bundler/setup.rb:17
        from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:110:in `gem_original_require'
        from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:110:in `require'
        from /Users/c4605/workSpace/readweekly/config/boot.rb:6
        from script/rails:5:in `require'
        from script/rails:5

Who know how i can change ruby version to 1.9.3 in cron job?

@javan
Copy link
Owner

javan commented Mar 25, 2013

Are you using RVM or rbenv to manage ruby versions?

@bolasblack
Copy link
Author

Yes, i am using RVM

@javan
Copy link
Owner

javan commented Mar 25, 2013

Any reason you're leaving out the -l from the default job_template? It's possible that's preventing RVM from loading.

@bolasblack
Copy link
Author

Thank you @javan , i resolved the problem, i changed the job_template become:

job_type :runner, "source $HOME/.rvm/scripts/rvm && rvm use 1.9.3-p392 && cd :path && script/rails runner -e :environment ':task' :output"

And it works now.

@JackWells
Copy link

The solution has no resemblance to the examples, which could explain the past 4 hours trying to solve this. I have RVM. I can verify all gems, rake, etc are accessible from the command-line where I run wherever; they should be getting passed and set-up automatically, right? I've tried every proposed solution in StackO, and there are many. None of them work. What is the closest thing to ... "rake "my_task" ... which I can put in the schedule.rb file so that it will find the pieces it needs to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants