Module: Legion::MCP::Patterns::Gossip
- Extended by:
- Logging::Helper
- Defined in:
- lib/legion/mcp/patterns/gossip.rb
Constant Summary collapse
- EXCHANGE_NAME =
'tbi.patterns'- ANNOUNCE_TTL =
86_400
Class Method Summary collapse
- .announce(pattern) ⇒ Object
- .instance_id ⇒ Object
- .receive(message) ⇒ Object
- .reset! ⇒ Object
- .transport_available? ⇒ Boolean
Class Method Details
.announce(pattern) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/legion/mcp/patterns/gossip.rb', line 17 def announce(pattern) log.debug("[mcp][pattern_gossip] action=announce transport_available=#{transport_available?}") return nil unless transport_available? exported = Patterns::Schema.export(pattern) = { action: 'announce', pattern_id: exported[:pattern_id], pattern: exported, origin: { instance_id: instance_id }, ttl: ANNOUNCE_TTL, version: 1 } Legion::Transport::Messages::Dynamic.new( function: "#{EXCHANGE_NAME}.announce", data: ).publish { published: true, pattern_id: exported[:pattern_id] } rescue StandardError => e handle_exception(e, level: :warn, operation: 'legion.mcp.pattern_gossip.announce') nil end |
.instance_id ⇒ Object
58 59 60 |
# File 'lib/legion/mcp/patterns/gossip.rb', line 58 def instance_id @instance_id ||= SecureRandom.uuid end |
.receive(message) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/legion/mcp/patterns/gossip.rb', line 42 def receive() log.debug("[mcp][pattern_gossip] action=receive valid=#{.is_a?(Hash) && .key?(:pattern)}") return nil unless .is_a?(Hash) && [:pattern] Patterns::Schema.import([:pattern], trust_level: :org) rescue StandardError => e handle_exception(e, level: :warn, operation: 'legion.mcp.pattern_gossip.receive') nil end |
.reset! ⇒ Object
62 63 64 |
# File 'lib/legion/mcp/patterns/gossip.rb', line 62 def reset! @instance_id = nil end |