Class: JayAPI::Elasticsearch::ClientFactory
- Inherits:
-
Object
- Object
- JayAPI::Elasticsearch::ClientFactory
- Defined in:
- lib/jay_api/elasticsearch/client_factory.rb
Overview
A factory class that creates an Elasticsearch Client object. More specifically, a JayAPI wrapper object over the Elasticsearch Client object.
Constant Summary collapse
- DEFAULT_ELASTICSEARCH_PORT =
The default port for the Elasticsearch cluster
9200
- WAIT_STRATEGIES =
Classes that define the available waiting strategies, used for deciding sleep time between the reconnections.
{ geometric: JayAPI::Abstract::GeometricWait, constant: JayAPI::Abstract::ConstantWait }.freeze
- MAX_ATTEMPTS =
The maximum number of connection attempts to be made.
4
- WAIT_INTERVAL =
The default wait time to be passed to the wait strategy class.
2
Instance Attribute Summary collapse
-
#cluster_url ⇒ Object
readonly
Returns the value of attribute cluster_url.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#create(max_attempts: MAX_ATTEMPTS, wait_strategy: :geometric, wait_interval: WAIT_INTERVAL) ⇒ JayAPI::Elasticsearch::Client
Returns the current instance of the Elasticsearch client, or creates a new one.
-
#initialize(cluster_url:, port: nil, logger: nil, **credentials) ⇒ ClientFactory
constructor
Creates a new instance of the class.
Constructor Details
#initialize(cluster_url:, port: nil, logger: nil, **credentials) ⇒ ClientFactory
Creates a new instance of the class. disabling :reek:ControlParameter
48 49 50 51 52 53 54 |
# File 'lib/jay_api/elasticsearch/client_factory.rb', line 48 def initialize(cluster_url:, port: nil, logger: nil, **credentials) @cluster_url = cluster_url @port = port || DEFAULT_ELASTICSEARCH_PORT @logger = logger || Logging.logger($stdout) @username = credentials[:username] @password = credentials[:password] end |
Instance Attribute Details
#cluster_url ⇒ Object (readonly)
Returns the value of attribute cluster_url.
32 33 34 |
# File 'lib/jay_api/elasticsearch/client_factory.rb', line 32 def cluster_url @cluster_url end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
32 33 34 |
# File 'lib/jay_api/elasticsearch/client_factory.rb', line 32 def port @port end |
Instance Method Details
#create(max_attempts: MAX_ATTEMPTS, wait_strategy: :geometric, wait_interval: WAIT_INTERVAL) ⇒ JayAPI::Elasticsearch::Client
Returns the current instance of the Elasticsearch client, or creates a new one.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/jay_api/elasticsearch/client_factory.rb', line 66 def create(max_attempts: MAX_ATTEMPTS, wait_strategy: :geometric, wait_interval: WAIT_INTERVAL) JayAPI::Elasticsearch::Client.new( ::Elasticsearch::Client.new( hosts: [host], log: false ), logger, max_attempts: max_attempts, wait_strategy: WAIT_STRATEGIES[wait_strategy].new(wait_interval: wait_interval, logger: logger) ) end |