From 15e1c9011a046d4c02c8b34c22d00724727e78a6 Mon Sep 17 00:00:00 2001 From: Brusk Awat Date: Thu, 13 Apr 2023 12:16:18 +0300 Subject: [PATCH] Adds circuit-breaking --- Gemfile.lock | 2 +- lib/outboxable/polling_publisher_worker.rb | 2 +- lib/outboxable/version.rb | 2 +- lib/templates/outbox.rb | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 26fc59a..2f65b8c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - outboxable (0.1.6) + outboxable (0.1.8) bunny (>= 2.19.0) connection_pool (~> 2.3.0) diff --git a/lib/outboxable/polling_publisher_worker.rb b/lib/outboxable/polling_publisher_worker.rb index 32507b1..45757dc 100644 --- a/lib/outboxable/polling_publisher_worker.rb +++ b/lib/outboxable/polling_publisher_worker.rb @@ -8,7 +8,7 @@ module Outboxable batch.each do |outbox| # This is to prevent a job from being retried too many times. Worst-case scenario is 1 minute delay in jobs. Outboxable::Worker.perform_async(outbox.id) - outbox.update(last_attempted_at: 1.minute.from_now, status: :processing) + outbox.update(last_attempted_at: 1.minute.from_now, status: :processing, allow_publish: false) end end end diff --git a/lib/outboxable/version.rb b/lib/outboxable/version.rb index c862b28..d33080e 100644 --- a/lib/outboxable/version.rb +++ b/lib/outboxable/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Outboxable - VERSION = '0.1.7' + VERSION = '0.1.8' end diff --git a/lib/templates/outbox.rb b/lib/templates/outbox.rb index e3b74b9..d4ca5b7 100644 --- a/lib/templates/outbox.rb +++ b/lib/templates/outbox.rb @@ -1,9 +1,9 @@ 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 } @@ -21,7 +21,7 @@ class Outbox < ApplicationRecord 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