Sha256: a659630f88f9a6cd00190f78aab1890891cd79a0f9ddefd9c6726d28ab251ccc

Contents?: true

Size: 1.23 KB

Versions: 20

Compression:

Stored size: 1.23 KB

Contents

module Instapusher
  class Executor

    attr_accessor :base

    delegate :job,              to: :base

    def initialize base
      @base = base
    end

    def execute cmd, index
      job.add_log("executing: #{cmd}")
      handle_error unless execute_using_popen3
    end

    private

    def handle_failure
      job.update_attributes(ended_at: Time.now, status: :failed)
      msg = "#{cmd} FAILED"
      job.add_log(msg)
      raise msg
    end

    # returns false if command fails
    def execute_using_popen3
      Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
        while line = stdout.gets
          job.add_log(line)
        end
        while line = stderr.gets
          job.add_log(line)
        end

        exit_status = wait_thr.value

        job.add_log("exist_status.success? is: #{exit_status.success?}")
        job.add_log("index is: #{index}")

        success = exit_status.success?
        failure = !success

        if failure && index == 1
          cmd = "git remote add  h#{branch_name} git@heroku.com:#{heroku_app_name}.git"
          job.add_log(cmd)
          return false unless system(cmd)
        elsif failure && index != 1
          return false
        end

        true
      end
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
instapusher-0.0.21 lib/instapusher/executor.rb
instapusher-0.0.20 lib/instapusher/executor.rb
instapusher-0.0.19 lib/instapusher/executor.rb
instapusher-0.0.18 lib/instapusher/executor.rb
instapusher-0.0.17 lib/instapusher/executor.rb
instapusher-0.0.16 lib/instapusher/executor.rb
instapusher-0.0.15 lib/instapusher/executor.rb
instapusher-0.0.14 lib/instapusher/executor.rb
instapusher-0.0.13 lib/instapusher/executor.rb
instapusher-0.0.12 lib/instapusher/executor.rb
instapusher-0.0.11 lib/instapusher/executor.rb
instapusher-0.0.10 lib/instapusher/executor.rb
instapusher-0.0.9 lib/instapusher/executor.rb
instapusher-0.0.8 lib/instapusher/executor.rb
instapusher-0.0.7 lib/instapusher/executor.rb
instapusher-0.0.6 lib/instapusher/executor.rb
instapusher-0.0.5 lib/instapusher/executor.rb
instapusher-0.0.4 lib/instapusher/executor.rb
instapusher-0.0.3 lib/instapusher/executor.rb
instapusher-0.0.2 lib/instapusher/executor.rb