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

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_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

#dataObject



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

Returns:

  • (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_finishedObject



37
38
39
# File 'lib/bramble/result.rb', line 37

def percent_finished
  (percent_mapped + percent_reduced) / 2
end

#running?Boolean

Returns:

  • (Boolean)


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

def running?
  started? && !finished?
end