mirror of
https://github.com/ditkrg/outboxable.git
synced 2026-01-22 22:06:47 +00:00
Separates polling publisher for mongoid from activerecord
This commit is contained in:
parent
64c23f9796
commit
a5153324d5
@ -10,7 +10,7 @@ module Outboxable
|
|||||||
|
|
||||||
class Configuration
|
class Configuration
|
||||||
ALLOWED_MESSAGE_BROKERS = %i[rabbitmq].freeze
|
ALLOWED_MESSAGE_BROKERS = %i[rabbitmq].freeze
|
||||||
ALLOWED_ORMS = %i[activerecord].freeze
|
ALLOWED_ORMS = %i[activerecord mongoid].freeze
|
||||||
|
|
||||||
attr_accessor :rabbitmq_host,
|
attr_accessor :rabbitmq_host,
|
||||||
:rabbitmq_port,
|
:rabbitmq_port,
|
||||||
|
|||||||
@ -4,6 +4,10 @@ module Outboxable
|
|||||||
sidekiq_options queue: 'critical'
|
sidekiq_options queue: 'critical'
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
|
Outboxable.configuration.orm == :mongoid ? perform_mongoid : perform_activerecord
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform_activerecord
|
||||||
Outbox.pending.where(last_attempted_at: [..Time.zone.now, nil]).find_in_batches(batch_size: 100).each do |batch|
|
Outbox.pending.where(last_attempted_at: [..Time.zone.now, nil]).find_in_batches(batch_size: 100).each do |batch|
|
||||||
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.
|
||||||
@ -12,5 +16,13 @@ module Outboxable
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def perform_mongoid
|
||||||
|
Outbox.pending.where(last_attempted_at: [..Time.zone.now, nil]).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, allow_publish: false)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user