Created
December 18, 2023 14:59
-
-
Save btwelch/0f3b3f9a26dbb39c4b807d899347b348 to your computer and use it in GitHub Desktop.
Tracked Retries
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
module TrackedRetries | |
def with_tracked_retries(sync_record, max_attempts: 3) | |
attempts = 0 | |
begin | |
attempts += 1 | |
sync_record.update(attempts: attempts) | |
yield | |
sync_record.update(success: true) | |
rescue => e | |
retry if attempts < max_attempts | |
error = ["Error: #{e.message}", "Type: #{e.class}", "Backtrace: #{e.backtrace.first(5).join("\n")}"].join(", ") | |
sync_record.update(success: false, error: error) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment