Class: TickrClient
- Inherits:
-
Object
- Object
- TickrClient
- Defined in:
- lib/tickr_client.rb
Instance Attribute Summary collapse
-
#cache_size ⇒ Object
Returns the value of attribute cache_size.
-
#replenish_cache_at ⇒ Object
Returns the value of attribute replenish_cache_at.
-
#servers ⇒ Object
Returns the value of attribute servers.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #get_ticket ⇒ Object
-
#initialize(opts) ⇒ TickrClient
constructor
A new instance of TickrClient.
Constructor Details
#initialize(opts) ⇒ TickrClient
Returns a new instance of TickrClient.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tickr_client.rb', line 9 def initialize(opts) self.servers = opts[:servers] self.timeout = opts[:timeout] || 1000 self.cache_size = opts[:cache_size] || 100 self.replenish_cache_at = opts[:replenish_cache_at] || 10 self.query_in_progress = false self.next_server_index = Random.new.rand(servers.count) self.tickets = ThreadSafe::Array.new fetch_tickets end |
Instance Attribute Details
#cache_size ⇒ Object
Returns the value of attribute cache_size.
7 8 9 |
# File 'lib/tickr_client.rb', line 7 def cache_size @cache_size end |
#replenish_cache_at ⇒ Object
Returns the value of attribute replenish_cache_at.
7 8 9 |
# File 'lib/tickr_client.rb', line 7 def replenish_cache_at @replenish_cache_at end |
#servers ⇒ Object
Returns the value of attribute servers.
7 8 9 |
# File 'lib/tickr_client.rb', line 7 def servers @servers end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/tickr_client.rb', line 7 def timeout @timeout end |
Instance Method Details
#get_ticket ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/tickr_client.rb', line 22 def get_ticket fetch_tickets if tickets.count == 0 this_ticket = tickets.shift fetch_tickets_async if tickets.count <= replenish_cache_at this_ticket end |