Class: Legion::Chat::NotificationBridge
- Inherits:
-
Object
- Object
- Legion::Chat::NotificationBridge
- Defined in:
- lib/legion/chat/notification_bridge.rb
Constant Summary collapse
- DEFAULT_PATTERNS =
{ 'alert.fired' => :critical, 'extinction.*' => :critical, 'governance.consent_violation' => :critical, 'runner.failure' => :info, 'worker.lifecycle' => :info, 'scheduler.mode_changed' => :info }.freeze
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
-
#has_urgent? ⇒ Boolean
rubocop:disable Naming/PredicatePrefix.
-
#initialize(queue: NotificationQueue.new) ⇒ NotificationBridge
constructor
A new instance of NotificationBridge.
- #pending_notifications(max_priority: :info) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(queue: NotificationQueue.new) ⇒ NotificationBridge
Returns a new instance of NotificationBridge.
19 20 21 22 |
# File 'lib/legion/chat/notification_bridge.rb', line 19 def initialize(queue: NotificationQueue.new) @queue = queue @patterns = load_patterns end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
17 18 19 |
# File 'lib/legion/chat/notification_bridge.rb', line 17 def queue @queue end |
Instance Method Details
#has_urgent? ⇒ Boolean
rubocop:disable Naming/PredicatePrefix
40 41 42 |
# File 'lib/legion/chat/notification_bridge.rb', line 40 def has_urgent? # rubocop:disable Naming/PredicatePrefix @queue.has_critical? end |
#pending_notifications(max_priority: :info) ⇒ Object
36 37 38 |
# File 'lib/legion/chat/notification_bridge.rb', line 36 def pending_notifications(max_priority: :info) @queue.pop_all(max_priority: max_priority) end |
#start ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/legion/chat/notification_bridge.rb', line 24 def start return unless defined?(Legion::Events) Legion::Events.on('*') do |event_name, payload| priority = match_priority(event_name) next unless priority = format_notification(event_name, payload) @queue.push(message: , priority: priority, source: event_name) end end |