2011-05-23 47 views
2
* * * * * /bin/bash -l -c 'cd /Users/boris/projects/MyApp/ && rails runner "Resque.enqueue(Place)"' 

基本上我需要做到以下幾點:計劃作業錯誤的幫助 - Rails的亞軍錯誤

  1. Load Ruby with RVM
  2. 導航到MyApp迪爾
  3. 運行以下行:rails runner "Resque.enqueue(Place)

以上cron似乎正在運行,但它與產生以下錯誤 怎麼回事?

/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 

回答

4

其實要做到這一點是使用RVM包裝的最佳方式。你可以創建一個這樣的包裝:

rvm wrapper [email protected] appname rails 

二進制文件可以是rails,rake,gem或其他你已經安裝的ruby二進制文件。會發生什麼是rvm創建一個包裝器,它會在執行rails命令之前獲取正確的rvm環境。在全系統RVM,包裝通常會被放置在/ usr /本地/ RVM /斌/

現在從cron你可以這樣做:

*/3 * * * * cd /path/to/your/app && appname_rails runner "Resque.enqueue(Place)" -e production 

這將CD插入您的應用程序目錄,執行你每3分鐘創建一個rvm包裝器。這個例子基於rails 3和生產環境。

0

很多搬到這裏來塊,這裏有一對夫婦的事情指針在您的環境(紅寶石,RVM,包)檢查 - 發表您的調查結果,並會從那裏。

Path's issue with bundler, to change or not to change?

Bundle bug

我猜命令運行的cron的罰款之外?如果您以不同的用戶身份運行您的cron作業,請檢查該用戶的環境。

1

您需要在任何Ruby代碼運行之前通過RVM通過正確的環境獲取源代碼。所以在命令中包括是這樣的:

source /usr/local/rvm/environments/[email protected] 

所以一個潛在的解決方案是:

SHELL=/bin/bash 
* * * * * source /{path_to_rvm_environment_for_ruby}@{gemset} && cd /Users/boris/projects/MyApp/ && rails runner "Resque.enqueue(Place)"'