1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-10-17 14:01:01 +00:00

With allow_silent, also check the presence of an explicit timestamp for Buffer#pending?

This commit is contained in:
Holger Just 2017-08-16 20:54:55 +02:00
parent d8300a125e
commit cca00408e2
2 changed files with 14 additions and 2 deletions

View File

@ -206,14 +206,16 @@ module Rackstash
# This flag denotes whether the current buffer holds flushable data. By
# default, a new buffer is not pending and will not be flushed to the sink.
# Each time there is a new message logged, this is set to `true` for the
# buffer. For changes of tags or fields, the `pending?` flag is only
# flipped to `true` if {#allow_silent?} is set to `true`.
# buffer. For changes of tags or fields or when setting the {#timestamp},
# the `pending?` flag is only flipped to `true` if {#allow_silent?} is set
# to `true`.
#
# @return [Boolean] `true` if the buffer has stored data which should be
# flushed.
def pending?
return true if @messages.any?
if allow_silent?
return true unless @timestamp.nil?
return true unless @fields.nil? || @fields.empty?
return true unless @tags.nil? || @tags.empty?
end

View File

@ -283,6 +283,11 @@ describe Rackstash::Buffer do
buffer.tags << 'alice'
expect(buffer.pending?).to be true
end
it 'is true if the timestamp was set' do
buffer.timestamp
expect(buffer.pending?).to be true
end
end
context 'with allow_silent: false' do
@ -304,6 +309,11 @@ describe Rackstash::Buffer do
buffer.tags << 'alice'
expect(buffer.pending?).to be false
end
it 'ignores the timestamp' do
buffer.timestamp
expect(buffer.pending?).to be false
end
end
end