Class: Cyclid::API::LogBuffer
- Inherits:
-
Object
- Object
- Cyclid::API::LogBuffer
- Defined in:
- app/cyclid/log_buffer.rb
Overview
Intelligent buffer which can be passed to plugins which need to collate output data from different commands during a job
Instance Method Summary collapse
-
#initialize(job_record = nil, websocket = nil) ⇒ LogBuffer
constructor
A new instance of LogBuffer.
-
#log ⇒ Object
Return a complete copy of the data from the buffer.
-
#read(length = nil) ⇒ Object
Non-destructively read any new data from the buffer.
-
#write(data) ⇒ Object
Append data to the log and send it on to any configured consumers.
Constructor Details
#initialize(job_record = nil, websocket = nil) ⇒ LogBuffer
Returns a new instance of LogBuffer.
71 72 73 74 75 |
# File 'app/cyclid/log_buffer.rb', line 71 def initialize(job_record = nil, websocket = nil) @job_record = job_record @websocket = websocket @buffer = StringFIFO.new end |
Instance Method Details
#log ⇒ Object
Return a complete copy of the data from the buffer
99 100 101 |
# File 'app/cyclid/log_buffer.rb', line 99 def log @buffer.string end |
#read(length = nil) ⇒ Object
Non-destructively read any new data from the buffer
94 95 96 |
# File 'app/cyclid/log_buffer.rb', line 94 def read(length = nil) @buffer.read(length) end |
#write(data) ⇒ Object
Append data to the log and send it on to any configured consumers
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/cyclid/log_buffer.rb', line 78 def write(data) # Append the new data to log @buffer.write data # Update the Job Record, if there is one if @job_record # XXX: This will destroy the database. Find a better method. @job_record.log = @buffer.string @job_record.save! end # Write to web socket @websocket&.write data end |