Class: ModelContextProtocol::Server::StreamableHttpTransport::NotificationQueue
- Inherits:
-
Object
- Object
- ModelContextProtocol::Server::StreamableHttpTransport::NotificationQueue
- Defined in:
- lib/model_context_protocol/server/streamable_http_transport/notification_queue.rb
Constant Summary collapse
- QUEUE_KEY_PREFIX =
"notifications:"- DEFAULT_MAX_SIZE =
1000
Instance Method Summary collapse
-
#initialize(redis_client, server_instance, max_size: DEFAULT_MAX_SIZE) ⇒ NotificationQueue
constructor
A new instance of NotificationQueue.
- #pop_all ⇒ Object
- #push(notification) ⇒ Object
Constructor Details
#initialize(redis_client, server_instance, max_size: DEFAULT_MAX_SIZE) ⇒ NotificationQueue
Returns a new instance of NotificationQueue.
9 10 11 12 13 14 |
# File 'lib/model_context_protocol/server/streamable_http_transport/notification_queue.rb', line 9 def initialize(redis_client, server_instance, max_size: DEFAULT_MAX_SIZE) @redis = redis_client @server_instance = server_instance @queue_key = "#{QUEUE_KEY_PREFIX}#{server_instance}" @max_size = max_size end |
Instance Method Details
#pop_all ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/model_context_protocol/server/streamable_http_transport/notification_queue.rb', line 25 def pop_all notification_jsons = @redis.multi do |multi| multi.lrange(@queue_key, 0, -1) multi.del(@queue_key) end.first return [] if notification_jsons.empty? notification_jsons.reverse.map do |notification_json| JSON.parse(notification_json) end end |
#push(notification) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/model_context_protocol/server/streamable_http_transport/notification_queue.rb', line 16 def push(notification) notification_json = notification.to_json @redis.multi do |multi| multi.lpush(@queue_key, notification_json) multi.ltrim(@queue_key, 0, @max_size - 1) end end |