Sha256: 614dd43f7d618ae1034f1cf7dea793131b60b81879c726164ce9aa90f271cbe5

Contents?: true

Size: 927 Bytes

Versions: 1

Compression:

Stored size: 927 Bytes

Contents

require 'open3'

module ForemanInventoryUpload
  module Async
    class ShellProcess < ::ApplicationJob
      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(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
        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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_inventory_upload-0.0.1.dev1 lib/foreman_inventory_upload/async/shell_process.rb