Class: TopologicalInventory::Providers::Common::SaveInventory::Saver
- Inherits:
-
Object
- Object
- TopologicalInventory::Providers::Common::SaveInventory::Saver
- Defined in:
- lib/topological_inventory/providers/common/save_inventory/saver.rb
Constant Summary collapse
- KAFKA_PAYLOAD_MAX_BYTES_DEFAULT =
As defined in: github.com/zendesk/ruby-kafka/blob/02f7e2816e1130c5202764c275e36837f57ca4af/lib/kafka/protocol/message.rb#L11-L17 There is at least 112 bytes that are added as a message header, so we need to keep room for that. Lets make it 512 bytes, just for sure.
750_000
- KAFKA_RESERVED_HEADER_SIZE =
512
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#max_bytes ⇒ Object
readonly
Returns the value of attribute max_bytes.
Instance Method Summary collapse
-
#initialize(client:, logger:, max_bytes: KAFKA_PAYLOAD_MAX_BYTES_DEFAULT) ⇒ Saver
constructor
A new instance of Saver.
-
#save(data) ⇒ Integer
A total number of parts that the payload was divided into.
Constructor Details
#initialize(client:, logger:, max_bytes: KAFKA_PAYLOAD_MAX_BYTES_DEFAULT) ⇒ Saver
Returns a new instance of Saver.
15 16 17 18 19 |
# File 'lib/topological_inventory/providers/common/save_inventory/saver.rb', line 15 def initialize(client:, logger:, max_bytes: KAFKA_PAYLOAD_MAX_BYTES_DEFAULT) @client = client @logger = logger @max_bytes = payload_max_size(max_bytes) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
21 22 23 |
# File 'lib/topological_inventory/providers/common/save_inventory/saver.rb', line 21 def client @client end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
21 22 23 |
# File 'lib/topological_inventory/providers/common/save_inventory/saver.rb', line 21 def logger @logger end |
#max_bytes ⇒ Object (readonly)
Returns the value of attribute max_bytes.
21 22 23 |
# File 'lib/topological_inventory/providers/common/save_inventory/saver.rb', line 21 def max_bytes @max_bytes end |
Instance Method Details
#save(data) ⇒ Integer
Returns A total number of parts that the payload was divided into.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/topological_inventory/providers/common/save_inventory/saver.rb', line 24 def save(data) inventory = data[:inventory].to_hash inventory_json = JSON.generate(inventory) if inventory_json.size < max_bytes save_inventory(inventory_json) return 1 else # GC can clean this up inventory_json = nil return save_payload_in_batches(inventory) end end |