Class: Bramble::Result

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(handle) ⇒ Result

Read the state for ‘handle` and store it in this object The state for `handle` may change during this time, but you won’t see the changes until you get a new result.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bramble/result.rb', line 10

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_atObject (readonly)

Returns the value of attribute finished_at.



5
6
7
# File 'lib/bramble/result.rb', line 5

def finished_at
  @finished_at
end

#handleObject (readonly)

Returns the value of attribute handle.



5
6
7
# File 'lib/bramble/result.rb', line 5

def handle
  @handle
end

#percent_mappedObject (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_reducedObject (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

#dataHash<Any, Any>



24
25
26
27
28
29
30
# File 'lib/bramble/result.rb', line 24

def data
  @data ||= begin
    key = Bramble::Keys.result_key(handle)
    results = storage.reduce_result_get(key)
    Bramble::Serialize.load(results)
  end
end

#finished?Boolean



33
34
35
36
# File 'lib/bramble/result.rb', line 33

def finished?
  # Possible to be greater than 1 because of floating-point arithmetic
  percent_finished >= 1
end

#percent_finishedFloat

How far along is this job? ‘.map` is considered 50%, `.reduce` is considered 50%



46
47
48
# File 'lib/bramble/result.rb', line 46

def percent_finished
  (percent_mapped + percent_reduced) / 2
end

#running?Boolean



39
40
41
# File 'lib/bramble/result.rb', line 39

def running?
  started? && !finished?
end