Sha256: 199cc53cef6717ae3c3048187f724dca29616279f1c7dcdad2f88f1864dd323a
Contents?: true
Size: 1.4 KB
Versions: 2
Compression:
Stored size: 1.4 KB
Contents
# frozen_string_literal: true require_relative 'periodic_sync' module Prefab class ContextShapeAggregator include Prefab::PeriodicSync attr_reader :data def initialize(client:, max_shapes:, sync_interval:) @max_shapes = max_shapes @client = client @name = 'context_shape_aggregator' @data = Concurrent::Set.new start_periodic_sync(sync_interval) end def push(context) return if @data.size >= @max_shapes context.contexts.each_pair do |name, name_context| name_context.to_h.each_pair do |key, value| @data.add [name, key, Prefab::ContextShape.field_type_number(value)] end end end def prepare_data duped = @data.dup @data.clear duped.inject({}) do |acc, (name, key, type)| acc[name] ||= {} acc[name][key] = type acc end end private def flush(to_ship, _) @pool.post do log_internal "Uploading context shapes for #{to_ship.values.size}" shapes = PrefabProto::ContextShapes.new( shapes: to_ship.map do |name, shape| PrefabProto::ContextShape.new( name: name, field_types: shape ) end ) result = @client.post('/api/v1/context-shapes', shapes) log_internal "Uploaded #{to_ship.values.size} shapes: #{result.status}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
prefab-cloud-ruby-0.24.5 | lib/prefab/context_shape_aggregator.rb |
prefab-cloud-ruby-0.24.4 | lib/prefab/context_shape_aggregator.rb |