Class: Gorgon::RuntimeRecorder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_state, runtime_filename) ⇒ RuntimeRecorder

Returns a new instance of RuntimeRecorder.



7
8
9
10
11
12
# File 'lib/gorgon/runtime_recorder.rb', line 7

def initialize(job_state, runtime_filename)
  @records = {}
  @job_state = job_state
  @job_state.add_observer(self)
  @runtime_filename = runtime_filename || ""
end

Instance Attribute Details

#recordsObject

Returns the value of attribute records.



5
6
7
# File 'lib/gorgon/runtime_recorder.rb', line 5

def records
  @records
end

Instance Method Details

#update(payload) ⇒ Object



14
15
16
17
# File 'lib/gorgon/runtime_recorder.rb', line 14

def update payload
  @records[payload[:filename]] = payload[:runtime] if payload[:action] == "finish"
  self.write_records_to_file if @job_state.is_job_complete?
end

#write_records_to_fileObject



19
20
21
22
23
24
25
26
# File 'lib/gorgon/runtime_recorder.rb', line 19

def write_records_to_file
  return if @runtime_filename.empty?
  make_directories
  @records = Hash[@records.sort_by{|filename, runtime| -1*runtime}]
  File.open(@runtime_filename, 'w') do |f|
    f.write(Yajl::Encoder.encode(@records, pretty: true))
  end
end