Sha256: 78cdc2040f61ae71250b2da5354cfffb0e52166e62929f572551e4d124a0c60b

Contents?: true

Size: 1.17 KB

Versions: 99

Compression:

Stored size: 1.17 KB

Contents

module ForemanInventoryUpload
  module Async
    class ProgressOutput
      def self.get(label)
        ProgressOutput.new(label, :reader)
      end

      def self.register(label)
        ProgressOutput.new(label, :writer)
      end

      def initialize(label, mode)
        @label = label
        @mode = mode
      end

      def buffer
        @buffer ||= begin
                      File.open(file_name, file_mode)
                    rescue Errno::ENOENT
                      StringIO.new
                    end
      end

      def full_output
        buffer.read
      end

      def write_line(line)
        buffer << line
        buffer.fsync
      end

      def close
        @buffer&.close
      end

      def status
        File.read(file_name(:status))
      rescue Errno::ENOENT
        ''
      end

      def status=(status)
        File.atomic_write(file_name(:status)) do |status_file|
          status_file.write(status)
        end
      end

      private

      def file_mode
        (@mode == :reader) ? 'r' : 'w'
      end

      def file_name(type = 'out')
        File.join(ForemanInventoryUpload.outputs_folder, "#{@label}.#{type}")
      end
    end
  end
end

Version data entries

99 entries across 99 versions & 2 rubygems

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