class Bramble::Result

This class exposes the data and some info about the state of the task

Attributes

finished_at[R]
handle[R]
percent_mapped[R]
percent_reduced[R]

Public Class Methods

new(handle) click to toggle source

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.

# 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

Public Instance Methods

data() click to toggle source

@return [Hash<Any, Any>] The `key => value` results of `.reduce`

# 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?() click to toggle source

@return [Boolean] True if all data has been mapped and reduced

# 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_finished() click to toggle source

How far along is this job? `.map` is considered 50%, `.reduce` is considered 50% @return [Float] Percent progress for this job

# File lib/bramble/result.rb, line 46
def percent_finished
  (percent_mapped + percent_reduced) / 2
end
running?() click to toggle source

@return [Boolean] True if the job has been started but it isn't finished yet

# File lib/bramble/result.rb, line 39
def running?
  started? && !finished?
end

Private Instance Methods

started?() click to toggle source
# File lib/bramble/result.rb, line 52
def started?
  @started ||= !!storage.get(Bramble::Keys.status_key(handle))
end
storage() click to toggle source
# File lib/bramble/result.rb, line 56
def storage
  Bramble::Storage
end