class Riffer::Rig::Runtime::JobLog
Constants
- CHUNK_BYTES
- DROPPED
- KEEP_BYTES
- MAX_BYTES
Public Class Methods
(IO output, String path) → void
Source
# File lib/riffer/rig/runtime/job_log.rb, line 21 def initialize(output, path) @output = output @path = path @mutex = Mutex.new @dropped = 0 file = File.new(path, 'a+b', 0o600) file.sync = true @copier = Thread.new { copy(file) } end
@rbs output: IO @rbs path: String @rbs return: void
Public Instance Methods
() → void
Source
# File lib/riffer/rig/runtime/job_log.rb, line 61 def close # Closing the pipe raises IOError in a copier blocked reading it. @output.close @copier.join end
@rbs return: void
(Float timeout) → void
Source
# File lib/riffer/rig/runtime/job_log.rb, line 56 def drain(timeout) @copier.join(timeout) end
@rbs timeout: Float @rbs return: void
(Integer offset, Integer limit) → [ String, Integer ]
Source
# File lib/riffer/rig/runtime/job_log.rb, line 34 def read(offset, limit) @mutex.synchronize do marker = marker_bytes # Offsets count the bytes the job has written rather than a place in the # file, so they stay valid when the head of the file is dropped. position = offset < @dropped ? 0 : marker + offset - @dropped size = File.size?(@path).to_i output = slice(limit, position) # The inner max covers a file that grew between the size and the read, # the outer one a removed file, which must not move the offset back. [output, [@dropped - marker + [position + output.bytesize, size].max, offset].max] end end
@rbs offset: Integer @rbs limit: Integer @rbs return: [String, Integer]
(Integer limit) → String
Source
# File lib/riffer/rig/runtime/job_log.rb, line 50 def tail(limit) @mutex.synchronize { slice(limit, [File.size?(@path).to_i - limit, 0].max) } end
@rbs limit: Integer @rbs return: String