Class: Bramble::Result
- Inherits:
-
Object
- Object
- Bramble::Result
- Defined in:
- lib/bramble/result.rb
Overview
This class exposes the data and some info about the state of the task
Instance Attribute Summary collapse
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#percent_mapped ⇒ Object
readonly
Returns the value of attribute percent_mapped.
-
#percent_reduced ⇒ Object
readonly
Returns the value of attribute percent_reduced.
Instance Method Summary collapse
- #data ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(handle) ⇒ Result
constructor
A new instance of Result.
- #percent_finished ⇒ Object
- #running? ⇒ Boolean
Constructor Details
#initialize(handle) ⇒ Result
Returns a new instance of Result.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bramble/result.rb', line 7 def initialize(handle) job_id = storage.get(Bramble::Keys.job_id_key(handle)) @handle = "#{handle}:#{job_id}" @percent_mapped = Bramble::State.percent_mapped(@handle) @percent_reduced = Bramble::State.percent_reduced(@handle) if finished? finished_at_ms = storage.get(Bramble::Keys.finished_at_key(@handle)).to_i @finished_at = Time.at(finished_at_ms) else @finished_at = nil end end |
Instance Attribute Details
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
5 6 7 |
# File 'lib/bramble/result.rb', line 5 def finished_at @finished_at end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
5 6 7 |
# File 'lib/bramble/result.rb', line 5 def handle @handle end |
#percent_mapped ⇒ Object (readonly)
Returns the value of attribute percent_mapped.
5 6 7 |
# File 'lib/bramble/result.rb', line 5 def percent_mapped @percent_mapped end |
#percent_reduced ⇒ Object (readonly)
Returns the value of attribute percent_reduced.
5 6 7 |
# File 'lib/bramble/result.rb', line 5 def percent_reduced @percent_reduced end |
Instance Method Details
#data ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/bramble/result.rb', line 20 def data @data ||= begin key = Bramble::Keys.result_key(handle) results = storage.reduce_result_get(key) Bramble::Serialize.load(results) end end |
#finished? ⇒ Boolean
28 29 30 31 |
# File 'lib/bramble/result.rb', line 28 def finished? # Possible to be greater than 1 because of floating-point arithmetic percent_finished >= 1 end |
#percent_finished ⇒ Object
37 38 39 |
# File 'lib/bramble/result.rb', line 37 def percent_finished (percent_mapped + percent_reduced) / 2 end |
#running? ⇒ Boolean
33 34 35 |
# File 'lib/bramble/result.rb', line 33 def running? started? && !finished? end |