Class: Bones::RPC::ReadPreference::Nearest
- Inherits:
-
Object
- Object
- Bones::RPC::ReadPreference::Nearest
- Includes:
- Selectable
- Defined in:
- lib/bones/rpc/read_preference/nearest.rb
Overview
Encapsulates behaviour around a nearest read preference.
Instance Attribute Summary
Attributes included from Selectable
Instance Method Summary collapse
-
#name ⇒ Symbol
Get the name for the read preference on the server side.
-
#with_node(cluster, &block) ⇒ Object
Execute the provided block on the node with the lowest latency, allowing either primary or secondary.
Methods included from Selectable
Instance Method Details
#name ⇒ Symbol
Get the name for the read preference on the server side.
20 21 22 |
# File 'lib/bones/rpc/read_preference/nearest.rb', line 20 def name :nearest end |
#with_node(cluster, &block) ⇒ Object
Note:
If tag sets are provided then selection will need to match the provided tags.
Execute the provided block on the node with the lowest latency, allowing either primary or secondary.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bones/rpc/read_preference/nearest.rb', line 44 def with_node(cluster, &block) with_retry(cluster) do nearest = cluster.nodes.sort_by(&:latency).first if nearest block.call(nearest) else raise Errors::ConnectionFailure, "No nodes available to select in the cluster" end end end |