Sha256: b6c265f904bd176041f178f921c114e74962ac67414f13389fb6cf26e69ec73f

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 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 = ProgressOutput.register(instance_label)
        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
        logger.debug("Finished job #{klass_name} with label #{instance_label}")
      ensure
        progress_output.close
      end

      def command
      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

2 entries across 2 versions & 1 rubygems

Version Path
foreman_rh_cloud-2.0.10 lib/foreman_inventory_upload/async/shell_process.rb
foreman_rh_cloud-2.0.9 lib/foreman_inventory_upload/async/shell_process.rb