Sha256: 32e93914c99cfe8d421799cede74ccfc48a2d104d7ce4d4f2d14956dbd84a081

Contents?: true

Size: 1.5 KB

Versions: 22

Compression:

Stored size: 1.5 KB

Contents

require 'open3'

module ForemanInventoryUpload
  module Async
    class ShellProcess < ::Actions::EntryAction
      include AsyncHelpers

      def plan(instance_label, more_inputs = {})
        inputs = more_inputs.merge(instance_label: instance_label)
        plan_self(inputs)
      end

      def run
        klass_name = self.class.name
        logger.debug("Starting #{klass_name} with label #{instance_label}")
        progress_output do |progress_output|
          Open3.popen2e(hash_to_s(env), *preprocess_command(command)) do |_stdin, stdout_stderr, wait_thread|
            progress_output.status = "Running in pid #{wait_thread.pid}"

            stdout_stderr.each do |out_line|
              progress_output.write_line(out_line)
            end

            progress_output.status = wait_thread.value.to_s
          end
        end
        logger.debug("Finished job #{klass_name} with label #{instance_label}")
      end

      def command
      end

      def progress_output
        progress_output = ProgressOutput.register(instance_label)
        yield(progress_output)
      ensure
        progress_output.close
      end

      def env
        {}
      end

      def logger
        Foreman::Logging.logger('background')
      end

      def rescue_strategy_for_self
        Dynflow::Action::Rescue::Fail
      end

      private

      def preprocess_command(command)
        command.kind_of?(Array) ? command : [command]
      end

      def instance_label
        input[:instance_label]
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
foreman_rh_cloud-5.0.46 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.45 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.44 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.43 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-6.0.42.2 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-6.0.42.1 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-6.0.43 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.42 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-6.0.42 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.41 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.39 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.38 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.37 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.36 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.35 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.34 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.33 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.32 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.31 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-5.0.30 lib/foreman_inventory_upload/async/shell_process.rb