Class: Gorgon::FailuresPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/gorgon/failures_printer.rb

Constant Summary collapse

DEFAULT_OUTPUT_FILE =
"/tmp/gorgon-failed-files.json"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, job_state) ⇒ FailuresPrinter

Returns a new instance of FailuresPrinter.



9
10
11
12
13
# File 'lib/gorgon/failures_printer.rb', line 9

def initialize(configuration, job_state)
  @job_state = job_state
  @job_state.add_observer(self)
  @output_file = configuration.fetch(:failed_files) { DEFAULT_OUTPUT_FILE }
end

Instance Attribute Details

#output_fileObject (readonly)

Returns the value of attribute output_file.



7
8
9
# File 'lib/gorgon/failures_printer.rb', line 7

def output_file
  @output_file
end

Instance Method Details

#update(payload) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/gorgon/failures_printer.rb', line 15

def update payload
  return unless @job_state.is_job_complete? || @job_state.is_job_cancelled?

  File.open(@output_file, 'w+') do |fd|
    fd.write(Yajl::Encoder.encode(failed_files + unfinished_files))
  end
end