Class: ForemanInventoryUpload::Async::ProgressOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_inventory_upload/async/progress_output.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, mode) ⇒ ProgressOutput

Returns a new instance of ProgressOutput.



13
14
15
16
# File 'lib/foreman_inventory_upload/async/progress_output.rb', line 13

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

Class Method Details

.get(label) ⇒ Object



4
5
6
# File 'lib/foreman_inventory_upload/async/progress_output.rb', line 4

def self.get(label)
  ProgressOutput.new(label, :reader)
end

.register(label) ⇒ Object



8
9
10
11
# File 'lib/foreman_inventory_upload/async/progress_output.rb', line 8

def self.register(label)
  TaskOutputLine.where(label: @label).delete_all
  ProgressOutput.new(label, :writer)
end

Instance Method Details

#closeObject



26
27
# File 'lib/foreman_inventory_upload/async/progress_output.rb', line 26

def close
end

#full_outputObject



18
19
20
# File 'lib/foreman_inventory_upload/async/progress_output.rb', line 18

def full_output
  TaskOutputLine.where(label: @label).order(:created_at).pluck(:line).join("\n")
end

#statusObject



29
30
31
# File 'lib/foreman_inventory_upload/async/progress_output.rb', line 29

def status
  TaskOutputStatus.where(label: @label).pluck(:status).first || ''
end

#status=(status) ⇒ Object



33
34
35
# File 'lib/foreman_inventory_upload/async/progress_output.rb', line 33

def status=(status)
  TaskOutputStatus.upsert({ label: @label, status: status }, unique_by: :label)
end

#write_line(line) ⇒ Object



22
23
24
# File 'lib/foreman_inventory_upload/async/progress_output.rb', line 22

def write_line(line)
  TaskOutputLine.create!(label: @label, line: line)
end