Module: Warren::BroadcastMessages
- Included in:
- ApplicationRecord
- Defined in:
- lib/warren/broadcast_messages.rb
Overview
Module Warren::BroadcastMessages provides methods to assist with setting up message broadcast
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #broadcast ⇒ Object
-
#queue_associated_for_broadcast ⇒ void
After save callback: configured via broadcasts_associated_via_warren Adds any associated records to the transaction, ensuring their after commit methods will fire.
- #queue_for_broadcast ⇒ Object
-
#warren ⇒ #<<, ...
Returns the configured warren.
Class Method Details
.included(base) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/warren/broadcast_messages.rb', line 33 def self.included(base) base.class_eval do class_attribute :associated_to_broadcast, instance_writer: false extend ClassMethods end end |
Instance Method Details
#broadcast ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/warren/broadcast_messages.rb', line 48 def broadcast # This results in borrowing a connection from the pool # per-message. Which isn't ideal. Ideally we'd either # check out a connection per thread or per transaction. # Any checked out connections will need to be checked back # in once the thread/transaction ends with high reliability. # So we're doing things the easy way until: # 1) Performance requires something more complicated # 2) We find a way to achieve the above without monkey-patching # or other complexity (Its probably possible) warren << Warren::Message.new(self) end |
#queue_associated_for_broadcast ⇒ void
This method returns an undefined value.
After save callback: configured via broadcasts_associated_via_warren Adds any associated records to the transaction, ensuring their after commit methods will fire.
68 69 70 71 72 |
# File 'lib/warren/broadcast_messages.rb', line 68 def queue_associated_for_broadcast associated_to_broadcast.each do |association| send(association).try(:add_to_transaction) end end |
#queue_for_broadcast ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/warren/broadcast_messages.rb', line 40 def queue_for_broadcast # Message rendering is slow in some cases. This # broadcasts an initial lightweight message which can # be picked up and rendered asynchronously # Borrows connection as per #broadcast warren << Warren::QueueBroadcastMessage.new(self) end |