lib/fwd/output.rb in fwd-0.3.0 vs lib/fwd/output.rb in fwd-0.3.1
- old
+ new
@@ -21,14 +21,15 @@
end
# Callback
def forward!
Dir[root.join("#{prefix}.*.closed")].each do |file|
- reserve(file) do |data|
+ ok = reserve(file) do |data|
logger.debug { "Flushing #{File.basename(file)}, #{data.size.fdiv(1024).round} kB" }
write(data)
end
+ break unless ok
end
end
# @param [String] binary data
def write(data)
@@ -43,15 +44,18 @@
return if File.size(file) < 1
target = Pathname.new(file.sub(/\.closed$/, ".reserved"))
FileUtils.mv file, target.to_s
- if yield(target.read)
+ result = yield(target.read)
+ if result
target.unlink
else
logger.error "Flushing of #{target} failed."
FileUtils.mv target.to_s, target.to_s.sub(/\.reserved$/, ".closed")
end
+
+ result
rescue Errno::ENOENT
# Ignore if file was alread flushed by another process
end
def forward(backend, data)
\ No newline at end of file