Class: Outbox
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Outbox
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/templates/mongoid_outbox.rb,
lib/templates/activerecrod_outbox.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #check_publishing ⇒ Object
- #publish ⇒ Object
- #set_idempotency_key ⇒ Object
- #set_last_attempted_at ⇒ Object
Instance Attribute Details
#allow_publish ⇒ Object
57 58 59 60 61 |
# File 'lib/templates/mongoid_outbox.rb', line 57 def allow_publish return true if @allow_publish.nil? @allow_publish end |
Instance Method Details
#check_publishing ⇒ Object
53 54 55 |
# File 'lib/templates/mongoid_outbox.rb', line 53 def check_publishing self.allow_publish = false if published? end |
#publish ⇒ Object
44 45 46 47 |
# File 'lib/templates/mongoid_outbox.rb', line 44 def publish Outboxable::Worker.perform_async(idempotency_key) update(status: :processing, last_attempted_at: 1.minute.from_now, allow_publish: false) end |
#set_idempotency_key ⇒ Object
49 50 51 |
# File 'lib/templates/mongoid_outbox.rb', line 49 def set_idempotency_key self.idempotency_key = SecureRandom.uuid if idempotency_key.blank? end |
#set_last_attempted_at ⇒ Object
40 41 42 |
# File 'lib/templates/mongoid_outbox.rb', line 40 def set_last_attempted_at self.last_attempted_at = 10.seconds.from_now end |