1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-12-19 15:01:12 +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 # 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. # 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 # 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 # buffer. For changes of tags or fields or when setting the {#timestamp},
# flipped to `true` if {#allow_silent?} is set to `true`. # 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 # @return [Boolean] `true` if the buffer has stored data which should be
# flushed. # flushed.
def pending? def pending?
return true if @messages.any? return true if @messages.any?
if allow_silent? if allow_silent?
return true unless @timestamp.nil?
return true unless @fields.nil? || @fields.empty? return true unless @fields.nil? || @fields.empty?
return true unless @tags.nil? || @tags.empty? return true unless @tags.nil? || @tags.empty?
end end

View File

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