class Fireworks::DDThread
Attributes
bytes_completed[R]
rate[R]
Public Class Methods
new(thread:, stderr:)
click to toggle source
# File lib/fireworks/block_device.rb, line 87 def initialize(thread:, stderr:) @thread = thread @stderr = stderr @eof = false @bytes_completed = 0 @rate = 0 @updated_at = nil end
Public Instance Methods
complete?()
click to toggle source
# File lib/fireworks/block_device.rb, line 96 def complete? !@thread.alive? && @eof end
up_to_date?()
click to toggle source
# File lib/fireworks/block_device.rb, line 114 def up_to_date? return false if @updated_at.nil? Time.now - @updated_at < 120 end
update_status()
click to toggle source
# File lib/fireworks/block_device.rb, line 100 def update_status usr1! # send signal to dump stderr sleep 0.1 # need a short sleep to let IO threads run buffer = attempt_read most_recent_status = buffer.to_s.split("\n").last return unless most_recent_status && (match = most_recent_status.match(/(\d+) bytes.*, (\d+(?:\.\d+)? \w+)\/s/)) @bytes_completed = match[1].to_i @rate = Filesize.from(match[2]).to_i @updated_at = Time.now end
Private Instance Methods
attempt_read()
click to toggle source
# File lib/fireworks/block_device.rb, line 121 def attempt_read @stderr.read_nonblock(8196) rescue Errno::EAGAIN, Errno::EWOULDBLOCK return # No data! rescue EOFError @eof = true end
usr1!()
click to toggle source
# File lib/fireworks/block_device.rb, line 129 def usr1! Process.kill('USR1', @thread.pid) if @thread.alive? end