Class: RSpectacles::Adapter::BatchedLogger
- Inherits:
-
Logger
- Object
- Logger
- RSpectacles::Adapter::BatchedLogger
show all
- Defined in:
- lib/rspectacles/adapter/batched_logger.rb
Instance Attribute Summary
Attributes inherited from Logger
#test_run_key
Instance Method Summary
collapse
Methods inherited from Logger
#config, #initialize, #log, #start, #uri
Instance Method Details
#batch_size ⇒ Object
15
16
17
|
# File 'lib/rspectacles/adapter/batched_logger.rb', line 15
def batch_size
config.batch_size
end
|
#flush_queue ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/rspectacles/adapter/batched_logger.rb', line 25
def flush_queue
return unless active?
return unless queued_messages.size > 0
HTTParty.post(full_uri, timeout: 5,
body: { examples: queued_messages }.to_json,
headers: { 'Content-Type' => 'application/json' })
@queued_messages = []
end
|
#queue(message) ⇒ Object
19
20
21
22
23
|
# File 'lib/rspectacles/adapter/batched_logger.rb', line 19
def queue(message)
return unless active?
queued_messages << message
flush_queue if queued_messages.count > batch_size
end
|
#queued_messages ⇒ Object
6
7
8
|
# File 'lib/rspectacles/adapter/batched_logger.rb', line 6
def queued_messages
@queued_messages ||= []
end
|
#stop ⇒ Object
10
11
12
13
|
# File 'lib/rspectacles/adapter/batched_logger.rb', line 10
def stop
super
flush_queue
end
|