Adds circuit-breaking

This commit is contained in:
Brusk Awat 2023-04-13 12:16:18 +03:00
parent 3e10bd9768
commit 15e1c9011a
Signed by: broosk1993
GPG Key ID: 5D20F7E02649F74E
4 changed files with 5 additions and 5 deletions

View File

@ -1,7 +1,7 @@
PATH
remote: .
specs:
outboxable (0.1.6)
outboxable (0.1.8)
bunny (>= 2.19.0)
connection_pool (~> 2.3.0)

View File

@ -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

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
module Outboxable
VERSION = '0.1.7'
VERSION = '0.1.8'
end

View File

@ -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