Class: Logbook::Agent
- Inherits:
-
Object
- Object
- Logbook::Agent
- Includes:
- Singleton
- Defined in:
- lib/logbook/agent.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#stop_processing ⇒ Object
readonly
Returns the value of attribute stop_processing.
Instance Method Summary collapse
- #add_entry(severity, facility, payload) ⇒ Object
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
- #process ⇒ Object
- #reset ⇒ Object
- #run_loop ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/logbook/agent.rb', line 6 def client @client end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
6 7 8 |
# File 'lib/logbook/agent.rb', line 6 def entries @entries end |
#stop_processing ⇒ Object (readonly)
Returns the value of attribute stop_processing.
6 7 8 |
# File 'lib/logbook/agent.rb', line 6 def stop_processing @stop_processing end |
Instance Method Details
#add_entry(severity, facility, payload) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/logbook/agent.rb', line 64 def add_entry(severity, facility, payload) entries.push( :severity => severity, :facility => facility, :payload => payload, :timestamp => Time.now.to_s ) end |
#process ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/logbook/agent.rb', line 40 def process @semaphore.synchronize { return if entries.empty? # Copying the queue @entries_to_send = entries.dup Logbook.logger.info("Sending #{@entries_to_send.size} entries to the server") begin @client.send_entries(@entries_to_send) rescue => e Logbook.logger.error("Error when sending data to the server: #{e.}") case e when Logbook::Client::NotAuthorized @stop_processing = true end ensure # Removing sent items from the queue anyway entries.shift(@entries_to_send.size) end } end |
#reset ⇒ Object
29 30 31 |
# File 'lib/logbook/agent.rb', line 29 def reset entries.clear end |
#run_loop ⇒ Object
33 34 35 36 37 38 |
# File 'lib/logbook/agent.rb', line 33 def run_loop while keep_running? process sleep Logbook.delay_between_requests end end |
#start ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/logbook/agent.rb', line 15 def start @keep_running = true @loop = Thread.new do run_loop end @loop['label'] = 'Logbook loop' end |