Class: Makara::Context
- Inherits:
-
Object
- Object
- Makara::Context
- Defined in:
- lib/makara/context.rb
Class Method Summary collapse
- .generate(seed = nil) ⇒ Object
- .get_current ⇒ Object
- .get_previous ⇒ Object
- .previously_stuck?(config_id) ⇒ Boolean
- .set_current(context) ⇒ Object
- .set_previous(context) ⇒ Object
-
.stick(context, config_id, ttl) ⇒ Object
Called by ‘Proxy#stick_to_master!` to stick subsequent requests to master.
- .stuck?(context, config_id) ⇒ Boolean
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_current ⇒ Object
24 25 26 |
# File 'lib/makara/context.rb', line 24 def get_current fetch(:makara_context_current) { generate } end |
.get_previous ⇒ Object
15 16 17 |
# File 'lib/makara/context.rb', line 15 def get_previous fetch(:makara_context_previous) { generate } end |
.previously_stuck?(config_id) ⇒ 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 |