Skip to content

Instantly share code, notes, and snippets.

@sanfrecce-osaka
Created October 29, 2019 00:29
Show Gist options
  • Save sanfrecce-osaka/a1bb7f8912d25201af53580fd638e799 to your computer and use it in GitHub Desktop.
Save sanfrecce-osaka/a1bb7f8912d25201af53580fd638e799 to your computer and use it in GitHub Desktop.
my_batch_executor.rb
class MyFatalError < StandardError; end
class MyRetryableError < StandardError; end
class MyBatchExecutor
def initialize(*batches)
@batches = batches
end
def execute
retryable = true
@batches.each.with_index(1) do |batch, i|
batch.call
rescue RuntimeError => e
puts "Item #{i} failed: #{e.class}, #{e.message}"
next
rescue MyFatalError => e
puts "Item #{i} failed: #{e.class}, #{e.message}"
return
rescue MyRetryableError => e
puts "Item #{i} failed: #{e.class}, #{e.message}"
if retryable
retryable = false
redo
else
retryable = true
next
end
end
puts 'Batch complete'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment