Sha256: a5f7da0a7c62934c4844ff12520eb6f20efd12868c713305e8fbb28fc13bcf67

Contents?: true

Size: 1.26 KB

Versions: 45

Compression:

Stored size: 1.26 KB

Contents

require 'open3'

module ForemanInventoryUpload
  module Async
    class ShellProcess < ::ApplicationJob
      include AsyncHelpers

      def perform(instance_label)
        klass_name = self.class.name
        logger.debug("Starting #{klass_name} with label #{instance_label}")
        progress_output_for(instance_label) 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_for(instance_label)
        progress_output = ProgressOutput.register(instance_label)
        yield(progress_output)
      ensure
        progress_output.close
      end

      def env
        {}
      end

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

      private

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

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
foreman_rh_cloud-4.0.36 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-3.0.33 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.35 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-3.0.32 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.32 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.31 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.30 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-3.0.29 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.29 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-3.0.28 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.27 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-3.0.26 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.26 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.25.1 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-3.0.25 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.25 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-3.0.24.1 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.24.1 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-3.0.24 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-4.0.24 lib/foreman_inventory_upload/async/shell_process.rb