Sha256: 3274f5430bd43752cad9d2f80f8be926f14dc769de72c63e5f465a4dde6dfcf5

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

module Instapusher
  class Executor

    attr_accessor :base

    delegate :job,              to: :base

    def initialize base
      raise 'boom'
      @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

5 entries across 5 versions & 1 rubygems

Version Path
instapusher-0.0.26 lib/instapusher/executor.rb
instapusher-0.0.25 lib/instapusher/executor.rb
instapusher-0.0.24 lib/instapusher/executor.rb
instapusher-0.0.23 lib/instapusher/executor.rb
instapusher-0.0.22 lib/instapusher/executor.rb