Class: Makara::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/makara/context.rb

Class Method Summary collapse

Class Method Details

.generate(seed = nil) ⇒ Object



10
11
12
13
# File 'lib/makara/context.rb', line 10

def generate(seed = nil)
  seed ||= "#{Time.now.to_i}#{Thread.current.object_id}#{rand(99999)}"
  Digest::MD5.hexdigest(seed)
end

.get_currentObject



24
25
26
# File 'lib/makara/context.rb', line 24

def get_current
  fetch(:makara_context_current) { generate }
end

.get_previousObject



15
16
17
# File 'lib/makara/context.rb', line 15

def get_previous
  fetch(:makara_context_previous) { generate }
end

.previously_stuck?(config_id) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/makara/context.rb', line 32

def previously_stuck?(config_id)
  previously_sticky.fetch(config_id) do
    stuck?(Makara::Context.get_previous, config_id)
  end
end

.set_current(context) ⇒ Object



28
29
30
# File 'lib/makara/context.rb', line 28

def set_current(context)
  set(:makara_context_current,context)
end

.set_previous(context) ⇒ Object



19
20
21
22
# File 'lib/makara/context.rb', line 19

def set_previous(context)
  previously_sticky.clear
  set(:makara_context_previous,context)
end

.stick(context, config_id, ttl) ⇒ Object

Called by ‘Proxy#stick_to_master!` to stick subsequent requests to master. They’ll see the current context as their previous context when they’re asking whether they should be stuck to master.



41
42
43
# File 'lib/makara/context.rb', line 41

def stick(context, config_id, ttl)
  Makara::Cache.write(cache_key_for(context, config_id), '1', ttl)
end

.stuck?(context, config_id) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/makara/context.rb', line 45

def stuck?(context, config_id)
  !!Makara::Cache.read(cache_key_for(context, config_id))
end