2016-03-15 18 views
1

我將應用程序部署到了capistrano的vps。 一切工作正常,但只有:環境任務。不知道如何構建任務「環境」當我將我的應用程序部署到Capistrano任務中的vps

這是我的代碼

namespace :deploy do 

desc 'Clear memcache' 
    task clear_memcache: :environment do 
    on roles(:app) , in: :sequence, wait: 2 do 
     ::Rails.cache.clear 
     CACHE.flush 
    end 
    end 

    after :finishing, :clear_memcache 

end 

但我總是得到這個錯誤。

#<RuntimeError: Don't know how to build task 'environment' (see --tasks)> 

我該如何解決這個問題? 謝謝!

回答

1

我認爲你在混合兩個概念。一個耙子任務和一個capistrano任務。 Rake任務確實使用:environment子任務,而Capistrano則沒有。 Capistrano任務無法(AFAIK)直接在服務器上的rails應用程序上下文中調用ruby代碼,這是rake任務所要做的。

你實際上可能需要的是定義都rake任務清除緩存和Capistrano的任務將調用部署服務器上的耙任務。

嘗試這些:

rake任務來清除緩存:

# put this in Rakefile or any other rake file under lib/tasks 
desc 'Clear memcache' 
task clear_memcache: :environment do 
    ::Rails.cache.clear 
    CACHE.flush 
end 

的Capistrano的任務來調用服務器上的耙:

# config/deploy/production.rb 
namespace :deploy do 

    desc 'Clear memcache' 
    task :clear_memcache do 
    on roles(:app) , in: :sequence, wait: 2 do 
     within release_path do 
     with rails_env: fetch(:rails_env) do 
      execute 'rake', 'clear_memcache' 
     end 
     end 
    end 
    end 

    after :finishing, :clear_memcache  
end 
+0

什麼是文件名的lib/tasks內的文件? – user3403614

+0

你可以用'.rake'擴展名來命名你喜歡的任何東西,例如'memcache.rake'就可以。 – BoraMa

+0

我做了這個文件clear_memcache.rake在lib /任務中添加了你的代碼,但仍然有untimeError:不知道如何構建任務'environment' – user3403614

相關問題