Class: Smplkit::FlagRegistrationBuffer Private
- Inherits:
-
Object
- Object
- Smplkit::FlagRegistrationBuffer
- Defined in:
- lib/smplkit/buffers.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Thread-safe batch buffer for flag declarations.
Use peek + commit(ids) for the send path so a failed POST leaves declarations queued for the next attempt; the legacy drain is unconditional and used only by tests.
Instance Method Summary collapse
- #add(declaration) ⇒ Object private
- #commit(ids) ⇒ Object private
- #drain ⇒ Object private
-
#initialize ⇒ FlagRegistrationBuffer
constructor
private
A new instance of FlagRegistrationBuffer.
- #peek ⇒ Object private
- #pending_count ⇒ Object private
Constructor Details
#initialize ⇒ FlagRegistrationBuffer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of FlagRegistrationBuffer.
81 82 83 84 85 |
# File 'lib/smplkit/buffers.rb', line 81 def initialize @seen = {} @pending = [] @lock = Mutex.new end |
Instance Method Details
#add(declaration) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/smplkit/buffers.rb', line 87 def add(declaration) @lock.synchronize do next if @seen.key?(declaration.id) @seen[declaration.id] = true item = { "id" => declaration.id, "type" => declaration.type, "default" => declaration.default } item["service"] = declaration.service if declaration.service item["environment"] = declaration.environment if declaration.environment @pending << item end end |
#commit(ids) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
103 104 105 106 107 108 |
# File 'lib/smplkit/buffers.rb', line 103 def commit(ids) return if ids.nil? || ids.empty? committed = ids.to_set @lock.synchronize { @pending.reject! { |item| committed.include?(item["id"]) } } end |
#drain ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
110 111 112 113 114 115 116 |
# File 'lib/smplkit/buffers.rb', line 110 def drain @lock.synchronize do batch = @pending @pending = [] batch end end |
#peek ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 |
# File 'lib/smplkit/buffers.rb', line 99 def peek @lock.synchronize { @pending.dup } end |
#pending_count ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 |
# File 'lib/smplkit/buffers.rb', line 118 def pending_count @lock.synchronize { @pending.length } end |