Class: SplitIoClient::Cache::Repositories::Events::MemoryRepository
- Inherits:
-
SplitIoClient::Cache::Repositories::EventsRepository
- Object
- SplitIoClient::Cache::Repository
- SplitIoClient::Cache::Repositories::EventsRepository
- SplitIoClient::Cache::Repositories::Events::MemoryRepository
- Defined in:
- lib/splitclient-rb/cache/repositories/events/memory_repository.rb
Constant Summary collapse
- EVENTS_MAX_SIZE_BYTES =
5242880
Instance Method Summary collapse
- #add(key, traffic_type, event_type, time, value, properties, event_size) ⇒ Object
- #batch ⇒ Object
- #clear ⇒ Object
-
#initialize(config, telemetry_runtime_producer) ⇒ MemoryRepository
constructor
A new instance of MemoryRepository.
Methods inherited from SplitIoClient::Cache::Repositories::EventsRepository
Methods inherited from SplitIoClient::Cache::Repository
Constructor Details
#initialize(config, telemetry_runtime_producer) ⇒ MemoryRepository
Returns a new instance of MemoryRepository.
8 9 10 11 12 13 |
# File 'lib/splitclient-rb/cache/repositories/events/memory_repository.rb', line 8 def initialize(config, telemetry_runtime_producer) @config = config @adapter = @config.events_adapter @size = 0 @telemetry_runtime_producer = telemetry_runtime_producer end |
Instance Method Details
#add(key, traffic_type, event_type, time, value, properties, event_size) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/splitclient-rb/cache/repositories/events/memory_repository.rb', line 15 def add(key, traffic_type, event_type, time, value, properties, event_size) @adapter.add_to_queue(m: , e: event(key, traffic_type, event_type, time, value, properties)) @size += event_size post_events if @size >= EVENTS_MAX_SIZE_BYTES || @adapter.length == @config.events_queue_size @telemetry_runtime_producer.record_events_stats(Telemetry::Domain::Constants::EVENTS_QUEUED, 1) rescue StandardError => e @config.log_found_exception(__method__.to_s, e) @telemetry_runtime_producer.record_events_stats(Telemetry::Domain::Constants::EVENTS_DROPPED, 1) end |
#batch ⇒ Object
32 33 34 35 36 |
# File 'lib/splitclient-rb/cache/repositories/events/memory_repository.rb', line 32 def batch return [] if @config.events_queue_size.zero? @adapter.get_batch(@config.events_queue_size) end |
#clear ⇒ Object
27 28 29 30 |
# File 'lib/splitclient-rb/cache/repositories/events/memory_repository.rb', line 27 def clear @size = 0 @adapter.clear end |