繁体   English   中英

当我在 Capistrano 任务中将我的应用程序部署到 vps 时,不知道如何构建任务“环境”

[英]Don't know how to build task 'environment' When i deploy my app to vps in Capistrano task

我使用 capistrano 将我的应用程序部署到 vps。 一切正常,但只有 :environment 任务。

这是我的代码

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)>

我怎样才能解决这个问题? 谢谢!

我认为您正在混合两个概念。 一个耙子任务和一个 capistrano 任务。 Rake 任务确实使用:environment子任务,而 capistrano 任务则不使用。 Capistrano 任务不能(AFAIK)在服务器上的 rails 应用程序的上下文中直接调用 ruby​​ 代码,这就是 rake 任务所做的。

您实际上可能想要的是定义一个清除缓存的 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

在服务器上调用 rake 的 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM