Sha256: 32a0bf5967f2d4760d1a1406ef28f9ade41cf0c35ac4861e34854eb801da405b

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 KB

Contents

namespace :rails do
  desc "Open the rails console on each of the remote servers"
  task :console do
    console_roles = [roles(:worker), roles(:app)].find(&:any?)
    on console_roles, primary: true do |host, user|
      run_interactively "RAILS_ENV=#{rails_env} bundle exec rails console"
    end
  end

  desc "Open the rails dbconsole on each of the remote servers"
  task :dbconsole do
    on roles(:db), primary: true do |host|
      run_interactively "RAILS_ENV=#{rails_env} bundle exec rails dbconsole"
    end
  end

  desc "Open the rails log"
  task :log do
    on roles(:app), primary: true do |host, user|
      filename = ENV['LOG'] || rails_env
      run_interactively %Q{tail -f log/#{filename}.log | grep --line-buffered --invert "Delayed::Backend::ActiveRecord::Job Load"}
    end
  end

  desc "Run a rake task"
  task :rake, :task_to_run do |_, parameters|
    task_to_run = parameters[:task_to_run]
    abort "Must supply task to run on remote server.\nUsage example: cap dev rails:rake[flipper:synchronize_features]" if task_to_run.nil?
    roles = [roles(:worker), roles(:app)].find(&:any?)
    on roles, primary: true do
      run_interactively "RAILS_ENV=#{rails_env} bundle exec rake #{task_to_run}"
    end
  end

  def run_interactively(command)
    port = host.port || 22
    puts "ssh #{host.user}@#{host} -p #{port} -t 'cd #{deploy_to}/current; #{command}'"
    exec "ssh #{host.user}@#{host} -p #{port} -t 'cd #{deploy_to}/current; #{command}'"
  end

  def rails_env
    fetch(:rails_env)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jefferies_tube-1.4 lib/jefferies_tube/capistrano/rails.rb
jefferies_tube-1.3 lib/jefferies_tube/capistrano/rails.rb
jefferies_tube-1.2 lib/jefferies_tube/capistrano/rails.rb
jefferies_tube-1.1.1 lib/jefferies_tube/capistrano/rails.rb
jefferies_tube-1.1.0 lib/jefferies_tube/capistrano/rails.rb
jefferies_tube-1.0.5 lib/jefferies_tube/capistrano/rails.rb