Class: Outboxable::PollingPublisherWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
lib/outboxable/polling_publisher_worker.rb

Instance Method Summary collapse

Instance Method Details

#performObject



5
6
7
# File 'lib/outboxable/polling_publisher_worker.rb', line 5

def perform
  Outboxable.configuration.orm == :mongoid ? perform_mongoid : perform_activerecord
end

#perform_activerecordObject



9
10
11
12
13
14
15
16
17
# File 'lib/outboxable/polling_publisher_worker.rb', line 9

def perform_activerecord
  Outbox.pending.where(last_attempted_at: [..Time.zone.now, nil]).find_in_batches(batch_size: 100).each do |batch|
    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, allow_publish: false)
    end
  end
end

#perform_mongoidObject



19
20
21
22
23
24
25
# File 'lib/outboxable/polling_publisher_worker.rb', line 19

def perform_mongoid
  Outbox.pending.any_of({ last_attempted_at: ..Time.zone.now }, { last_attempted_at: 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.idempotency_key)
    outbox.update(last_attempted_at: 1.minute.from_now, status: :processing, allow_publish: false)
  end
end