Skip to content

Commit

Permalink
Add limiter for copay batch processing (#12910)
Browse files Browse the repository at this point in the history
* Add limiter for batch processing

* Adjust limit numbers

* Move to concurrent approach

* Break out from batch

* Decrease concurrent thread count

* Revert past decrease

* Move throttle to class method

* Make static limiter

* Lint

* Lint pt 2
  • Loading branch information
Scott James authored Jun 6, 2023
1 parent 1fb8e34 commit 42922ec
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/workers/copay_notifications/parse_new_statements_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ class ParseNewStatementsJob

sidekiq_options retry: false

def self.throttle
return Sidekiq::Limiter.unlimited if Rails.env.test?

Sidekiq::Limiter.concurrent('new-copay-statements', 8, wait_timeout: 259_200,
lock_timeout: 120)
end

LIMITER = throttle

def perform(statements_json_byte)
# Decode and parse large json file (~60-90k objects)
statements_json = Oj.load(Base64.decode64(statements_json_byte))

unique_statements = statements_json.uniq { |statement| statement['veteranIdentifier'] }

batch = Sidekiq::Batch.new

unique_statements.each do |statement|
CopayNotifications::NewStatementNotificationJob.perform_async(statement)
LIMITER.within_limit do
batch.jobs do
CopayNotifications::NewStatementNotificationJob.perform_async(statement)
end
end
end
end
end
Expand Down

0 comments on commit 42922ec

Please sign in to comment.