Module: Outboxer::Publisher
- Defined in:
- lib/outboxer/publisher.rb
Class Method Summary collapse
-
.publish(poll: 1, backoff: ->(current_backoff) { [current_backoff * 2, 5 * 60].min }) {|Hash| ... } ⇒ void
Publishes messages from the Outboxer queue.
-
.stop ⇒ void
Stops the publishing process.
Class Method Details
.publish(poll: 1, backoff: ->(current_backoff) { [current_backoff * 2, 5 * 60].min }) {|Hash| ... } ⇒ void
This method returns an undefined value.
Publishes messages from the Outboxer queue.
This method will continue to publish messages from the queue as long as @publishing is set to true. It uses an ActiveRecord connection to handle database interactions.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/outboxer/publisher.rb', line 40 def publish(poll: 1, backoff: ->(current_backoff) { [current_backoff * 2, 5 * 60].min }) @publishing = true ActiveRecord::Base.connection_pool.with_connection do while @publishing = dequeue(backoff: backoff) if .nil? sleep poll next end begin yield message: ., logger: @logger rescue StandardError => exception failed( outboxer_message: , backoff: backoff, exception: exception) next end published( outboxer_message: , backoff: backoff) end end end |
.stop ⇒ void
Note:
This method will stop the current message publishing process It is a safe way to interrupt the publishing process at any point.
This method returns an undefined value.
Stops the publishing process.
137 138 139 |
# File 'lib/outboxer/publisher.rb', line 137 def stop @publishing = false end |