Module: Bramble::State

Extended by:
Keys
Defined in:
lib/bramble/state.rb

Constant Summary collapse

SEPARATOR =
":"

Class Method Summary collapse

Methods included from Keys

data_key, finished_at_key, job_id_key, keys_key, map_finished_count_key, map_total_count_key, namespace, reduce_finished_count_key, reduce_total_count_key, result_key, status_key

Class Method Details

.clear_job(handle) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/bramble/state.rb', line 27

def clear_job(handle)
  handle_name, job_id = handle.split(SEPARATOR)
  storage.delete(job_id_key(handle_name))
  storage.delete(status_key(handle))
  clear_reduce(handle)
  clear_map(handle)
end

.clear_map(handle) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/bramble/state.rb', line 49

def clear_map(handle)
  map_group_keys = storage.map_keys_get(keys_key(handle))
  map_group_keys.each do |group_key|
    storage.delete(data_key(handle, group_key))
  end
  storage.delete(keys_key(handle))
  storage.delete(map_total_count_key(handle))
  storage.delete(map_finished_count_key(handle))
end

.clear_reduce(handle) ⇒ Object



59
60
61
62
63
64
# File 'lib/bramble/state.rb', line 59

def clear_reduce(handle)
  storage.delete(reduce_total_count_key(handle))
  storage.delete(reduce_finished_count_key(handle))
  storage.delete(result_key(handle))
  storage.delete(finished_at_key(handle))
end

.percent_mapped(handle) ⇒ Object



35
36
37
38
39
40
# File 'lib/bramble/state.rb', line 35

def percent_mapped(handle)
  percent_between_keys(
    map_total_count_key(handle),
    map_finished_count_key(handle)
  )
end

.percent_reduced(handle) ⇒ Object



42
43
44
45
46
47
# File 'lib/bramble/state.rb', line 42

def percent_reduced(handle)
  percent_between_keys(
    reduce_total_count_key(handle),
    reduce_finished_count_key(handle)
  )
end

.running?(handle) ⇒ Boolean

Run the block and return true if the ‘job_id` is still active

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'lib/bramble/state.rb', line 8

def running?(handle)
  handle_name, job_id = handle.split(SEPARATOR)
  is_running = storage.get(job_id_key(handle_name)) == job_id
  if block_given?
    yield
  end
  is_running
end

.start_job(handle) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/bramble/state.rb', line 17

def start_job(handle)
  handle_name, job_id = handle.split(SEPARATOR)
  previous_job_id = storage.get(job_id_key(handle_name))
  if previous_job_id
    clear_job("#{handle_name}:#{previous_job_id}")
  end
  storage.set(status_key(handle), "started")
  storage.set(job_id_key(handle_name), job_id)
end