lib/templates/outbox.rb in outboxable-0.1.7 vs lib/templates/outbox.rb in outboxable-0.1.8

- old
+ new

@@ -1,11 +1,11 @@ class Outbox < ApplicationRecord attribute :allow_publish, :boolean, default: true + before_save :check_publishing # Callbacks before_create :set_last_attempted_at - before_save :check_publishing after_commit :publish, if: :allow_publish? # Enums enum status: { pending: 0, processing: 1, published: 2, failed: 3 } enum size: { single: 0, batch: 1 } @@ -19,10 +19,10 @@ self.last_attempted_at = 10.seconds.from_now end def publish Outboxable::Worker.perform_async(id) - update(status: :processing, last_attempted_at: 1.minute.from_now) + update(status: :processing, last_attempted_at: 1.minute.from_now, allow_publish: false) end def check_publishing self.allow_publish = false if published? end