Sha256: 07bfe783b04f4da7b1daa7737cb61bb83d47728766e992aa7345d3fcd3478776

Contents?: true

Size: 1.12 KB

Versions: 14

Compression:

Stored size: 1.12 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), 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
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
foreman_rh_cloud-1.0.18 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-1.0.17 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-1.0.16 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-1.0.15 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-1.0.14 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-0.9.14 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-0.9.13.1 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-1.0.13.1 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-0.9.13 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-1.0.13 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-0.9.12 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-1.0.12 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-0.9.11 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-1.0.11 lib/foreman_inventory_upload/async/shell_process.rb