Created
October 29, 2019 00:29
-
-
Save sanfrecce-osaka/a1bb7f8912d25201af53580fd638e799 to your computer and use it in GitHub Desktop.
my_batch_executor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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