LoginSignup
2
2

More than 5 years have passed since last update.

Capistranoで新しいrake taskを実行するときの注意

Last updated at Posted at 2017-07-13

capコマンドでrake taskを実行するときの話しではなく、rake taskをdeply時に実行するようにしたときの話しです。言葉だと想像しにくいと思うので、コードで書くと

namespace :new_task do
  desc 'Exeute new task'
  task :new_task do
    on roles(:db) do |host|
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :rake, 'new_task:new_task'
        end
      end
    end
  end
end

after 'deploy:migrate', 'new_task:new_task'

こんな感じにmigrateの後にrake new_task:new_taskを常に実行したいときのケースです。

肝はrelease_path内でtaskを実行することです。

既にdeploy済みのコードにrake taskがある場合、current_pathでも問題ないのですが、これからdeployするコードに追加したrake taskを実行する場合、エラーになります。これはdeployが完了したときに、current_pathのシムリンクが張り替えられるため、current_path内のコードにrake taskが存在しません。なので、これからdeployするコードに追加したrake taskを実行する場合は、release_pathでrake taskを実行する必要があります。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2