Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

Commit

Permalink
fix(load-retry): Correct issue where Load Worker wasnt retrying when …
Browse files Browse the repository at this point in the history
…the API responded with a 500
  • Loading branch information
richardmatthewsdev committed Apr 16, 2024
1 parent 540f89c commit 6a4cbc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 12 additions & 1 deletion app/sidekiq/load_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,21 @@ def perform(harvest_job_id, records, api_record_id = nil)
job_end
end

def log_retry_attempt
proc do |exception, try, elapsed_time, next_interval|
if defined?(Sidekiq)
::Sidekiq.logger.info("
#{exception.class}: '#{exception.message}':
#{try} tries in #{elapsed_time} seconds and
#{next_interval} seconds until the next try.")
end
end
end

# :reek:UncommunicativeVariableName
# this reek has been ignored as 'e' is the variable name wanted by Rubocop
def process_batch(batch, api_record_id)
::Retriable.retriable(tries: 5, base_interval: 1, multiplier: 2) do
::Retriable.retriable(tries: 10, base_interval: 1, multiplier: 2, on_retry: log_retry_attempt) do
Load::Execution.new(batch, @harvest_job, api_record_id).call

@harvest_report.increment_records_loaded!(batch.count)
Expand Down
14 changes: 9 additions & 5 deletions app/supplejack/load/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ def initialize(records, harvest_job, api_record_id = nil)
end

def call
if @harvest_definition.harvest?
harvest_request
elsif @harvest_definition.enrichment?
enrichment_request
end
response = if @harvest_definition.harvest?
harvest_request
elsif @harvest_definition.enrichment?
enrichment_request
end

return unless response.status == 500

raise StandardError, 'Destination API responded with status 500'
end

private
Expand Down

0 comments on commit 6a4cbc4

Please sign in to comment.