class Google::Cloud::Logging::AsyncWriter::Batch

@private

Attributes

created_at[R]
entries[R]

Public Class Methods

new(writer) click to toggle source
# File lib/google/cloud/logging/async_writer.rb, line 463
def initialize writer
  @writer = writer
  @entries = []
  @entries_bytes = 2 # initial size w/ partial_success
  @created_at = nil
end

Public Instance Methods

add(entry, addl_bytes: nil) click to toggle source
# File lib/google/cloud/logging/async_writer.rb, line 470
def add entry, addl_bytes: nil
  addl_bytes ||= addl_bytes_for entry
  @entries << entry
  @entries_bytes += addl_bytes
  @created_at ||= Time.now
  nil
end
addl_bytes_for(entry) click to toggle source
# File lib/google/cloud/logging/async_writer.rb, line 507
def addl_bytes_for entry
  entry.to_grpc.to_proto.bytesize + 2
end
publish_at() click to toggle source
# File lib/google/cloud/logging/async_writer.rb, line 496
def publish_at
  return nil if @created_at.nil?
  @created_at + @writer.interval
end
publish_wait() click to toggle source
# File lib/google/cloud/logging/async_writer.rb, line 501
def publish_wait
  publish_wait = publish_at - Time.now
  return 0 if publish_wait.negative?
  publish_wait
end
ready?() click to toggle source
# File lib/google/cloud/logging/async_writer.rb, line 490
def ready?
  @entries.count >= @writer.max_count ||
    @entries_bytes >= @writer.max_bytes ||
    (@created_at.nil? || (publish_at < Time.now))
end
try_add(entry) click to toggle source
# File lib/google/cloud/logging/async_writer.rb, line 478
def try_add entry
  addl_bytes = addl_bytes_for entry
  new_message_count = @entries.count + 1
  new_message_bytes = @entries_bytes + addl_bytes
  if new_message_count > @writer.max_count ||
     new_message_bytes >= @writer.max_bytes
    return false
  end
  add entry, addl_bytes: addl_bytes
  true
end