Skip to content

Commit

Permalink
Add PollingReceiverWorker class to handle inbox processing
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadnawzad committed Jan 21, 2024
1 parent 90e8fca commit a7d02b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/inboxable/polling_receiver_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Inboxable
class PollingReceiverWorker
include Sidekiq::Job

def perform
perform_activerecord
end

def perform_activerecord
Inbox.pending.where(last_attempted_at: [..Time.zone.now, nil]).find_in_batches(batch_size: ENV.fetch('INBOXABLE__BATCH_SIZE', 100).to_i).each do |batch|
batch.each do |inbox|
inbox.processor_class_name.constantize.perform_async(inbox.id)
inbox.update(last_attempted_at: 1.minute.from_now, status: :processing, allow_publish: false)
end
end
end
end
end
7 changes: 7 additions & 0 deletions sig/inboxable/polling_receiver_worker.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Inboxable
class PollingReceiverWorker
def initialize: -> void
def perform: -> void
def perform_activerecord: -> void
end
end

0 comments on commit a7d02b8

Please sign in to comment.