Class: Chillout::Client
- Inherits:
-
Object
- Object
- Chillout::Client
- Extended by:
- Forwardable
- Defined in:
- lib/chillout/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #enqueue(creations) ⇒ Object
-
#initialize(config_or_api_key, options = {}) {|@config| ... } ⇒ Client
constructor
A new instance of Client.
- #start_worker ⇒ Object
- #worker_running? ⇒ Boolean
Constructor Details
#initialize(config_or_api_key, options = {}) {|@config| ... } ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chillout/client.rb', line 22 def initialize(config_or_api_key, = {}) build_config(config_or_api_key, ) yield @config if block_given? @logger = PrefixedLogger.new("Chillout", @config.logger) @http_client = HttpClient.new(@config, logger).freeze @event_data_builder = EventDataBuilder.new(@config).freeze @server_side = ServerSide.new(@event_data_builder, @http_client).freeze @dispatcher = Dispatcher.new(@server_side).freeze @queue = Queue.new @worker_mutex = Mutex.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
18 19 20 |
# File 'lib/chillout/client.rb', line 18 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
19 20 21 |
# File 'lib/chillout/client.rb', line 19 def logger @logger end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
20 21 22 |
# File 'lib/chillout/client.rb', line 20 def queue @queue end |
Instance Method Details
#enqueue(creations) ⇒ Object
37 38 39 40 41 |
# File 'lib/chillout/client.rb', line 37 def enqueue(creations) start_worker @logger.info "Creations were enqueued." @queue << creations end |
#start_worker ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chillout/client.rb', line 47 def start_worker return if worker_running? @worker_mutex.synchronize do return if worker_running? @worker_thread = Thread.new do begin worker = Worker.new(@dispatcher, @queue, @logger) worker.run ensure @logger.flush end end end end |
#worker_running? ⇒ Boolean
43 44 45 |
# File 'lib/chillout/client.rb', line 43 def worker_running? @worker_thread && @worker_thread.alive? end |