Sha256: 26cd75a3af82c56ae9d1f259ae5fde6cd5165979eede0a5a7950fe471944a69b

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

module Shuttle
  class Task
    def initialize(deploy, task_name, allow_failures = false)
      @deploy         = deploy
      @task_name      = task_name
      @allow_failures = allow_failures
    end

    def run
      commands = find_task_commands(@task_name)
      
      if commands.nil?
        @deploy.error("Unable to find task: #{@task_name}")
      end

      commands.each do |cmd|
        execute(@task_name, cmd, @allow_failures)
      end
    end

    private

    def find_task_commands(name)
      return unless @deploy.config.tasks.kind_of?(Hash)

      if @deploy.config.tasks[name]
        commands = [@deploy.config.tasks[name]]
        commands.flatten.compact
      end
    end

    def execute(task, cmd, allow_failures)
      @deploy.log %{Executing [task=#{task}] "#{cmd.strip}"}

      command = cmd

      if @deploy.ssh.directory_exists?(@deploy.release_path)
        command = "cd #{@deploy.release_path} && #{command}"
      end

      result = @deploy.ssh.run(command)

      if result.failure? && allow_failures == false
        @deploy.error("Failed: #{result.output}")
      else
        if !result.output.empty?
          @deploy.stream_output(result.output)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shuttle-deploy-0.4.0 lib/shuttle/task.rb
shuttle-deploy-0.3.3 lib/shuttle/task.rb
shuttle-deploy-0.3.2 lib/shuttle/task.rb
shuttle-deploy-0.3.1 lib/shuttle/task.rb
shuttle-deploy-0.3.0 lib/shuttle/task.rb
shuttle-deploy-0.3.0.beta1 lib/shuttle/task.rb