Class: Determinator::Retrieve::Routemaster
- Inherits:
-
Object
- Object
- Determinator::Retrieve::Routemaster
- Defined in:
- lib/determinator/retrieve/routemaster.rb
Overview
A storage and retrieval engine for Determinator using routemaster-drain.
To use this correctly you will need the following environment variables set to appropriate values for your instance of Routemaster:
ROUTEMASTER_DRAIN_TOKENS ROUTEMASTER_DRAIN_REDIS ROUTEMASTER_CACHE_REDIS ROUTEMASTER_CACHE_AUTH ROUTEMASTER_QUEUE_NAME ROUTEMASTER_CALLBACK_URL
Constant Summary collapse
- CALLBACK_PATH =
(URI.parse(ENV['ROUTEMASTER_CALLBACK_URL']).path rescue '/events').freeze
Instance Attribute Summary collapse
-
#routemaster_app ⇒ Object
readonly
Returns the value of attribute routemaster_app.
Class Method Summary collapse
Instance Method Summary collapse
-
#configure_rails_router(route_mapper) ⇒ Object
Automatically configures the rails router to listen for Features with routemaster.
-
#initialize(discovery_url:) ⇒ Routemaster
constructor
A new instance of Routemaster.
- #retrieve(feature_name) ⇒ Object
Constructor Details
#initialize(discovery_url:) ⇒ Routemaster
Returns a new instance of Routemaster.
25 26 27 28 29 30 31 32 33 |
# File 'lib/determinator/retrieve/routemaster.rb', line 25 def initialize(discovery_url:) client = ::Routemaster::APIClient.new( response_class: ::Routemaster::Responses::HateoasResponse ) @routemaster = client.discover(discovery_url) @routemaster_app = ::Routemaster::Drain::Caching.new( siphon_events: { 'features' => RoutemasterFeatureIdCacheWarmer } ) end |
Instance Attribute Details
#routemaster_app ⇒ Object (readonly)
Returns the value of attribute routemaster_app.
20 21 22 |
# File 'lib/determinator/retrieve/routemaster.rb', line 20 def routemaster_app @routemaster_app end |
Class Method Details
.index_cache_key(feature_name) ⇒ Object
66 67 68 |
# File 'lib/determinator/retrieve/routemaster.rb', line 66 def self.index_cache_key(feature_name) "determinator_index:#{feature_name}" end |
Instance Method Details
#configure_rails_router(route_mapper) ⇒ Object
Automatically configures the rails router to listen for Features with routemaster
62 63 64 |
# File 'lib/determinator/retrieve/routemaster.rb', line 62 def configure_rails_router(route_mapper) route_mapper.mount routemaster_app, at: CALLBACK_PATH end |
#retrieve(feature_name) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/determinator/retrieve/routemaster.rb', line 35 def retrieve(feature_name) key = self.class.index_cache_key(feature_name) feature_id = ::Routemaster::Config.cache_redis.get(key) return unless feature_id obj = @routemaster.feature.show(feature_id) Feature.new( name: obj.body.name, identifier: obj.body.identifier, bucket_type: obj.body.bucket_type, target_groups: obj.body.target_groups.map { |tg| TargetGroup.new( rollout: tg.rollout, constraints: tg.constraints.to_h ) }, variants: obj.body.variants.to_h, overrides: obj.body.overrides.to_h ) rescue ::Routemaster::Errors::ResourceNotFound nil end |