Class: 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.



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

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.



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

def records
  @records
end

Instance Method Details

#update(payload) ⇒ Object



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

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



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

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