mirror of
https://github.com/ditkrg/outboxable.git
synced 2026-01-22 22:06:47 +00:00
Adds circuit-breaking
This commit is contained in:
parent
3e10bd9768
commit
15e1c9011a
@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
outboxable (0.1.6)
|
outboxable (0.1.8)
|
||||||
bunny (>= 2.19.0)
|
bunny (>= 2.19.0)
|
||||||
connection_pool (~> 2.3.0)
|
connection_pool (~> 2.3.0)
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ module Outboxable
|
|||||||
batch.each do |outbox|
|
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.
|
# 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)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Outboxable
|
module Outboxable
|
||||||
VERSION = '0.1.7'
|
VERSION = '0.1.8'
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
class Outbox < ApplicationRecord
|
class Outbox < ApplicationRecord
|
||||||
attribute :allow_publish, :boolean, default: true
|
attribute :allow_publish, :boolean, default: true
|
||||||
|
|
||||||
|
before_save :check_publishing
|
||||||
# Callbacks
|
# Callbacks
|
||||||
before_create :set_last_attempted_at
|
before_create :set_last_attempted_at
|
||||||
before_save :check_publishing
|
|
||||||
after_commit :publish, if: :allow_publish?
|
after_commit :publish, if: :allow_publish?
|
||||||
# Enums
|
# Enums
|
||||||
enum status: { pending: 0, processing: 1, published: 2, failed: 3 }
|
enum status: { pending: 0, processing: 1, published: 2, failed: 3 }
|
||||||
@ -21,7 +21,7 @@ class Outbox < ApplicationRecord
|
|||||||
|
|
||||||
def publish
|
def publish
|
||||||
Outboxable::Worker.perform_async(id)
|
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
|
end
|
||||||
|
|
||||||
def check_publishing
|
def check_publishing
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user