Module: ThreadSafeUniquenessRecord

Defined in:
lib/thread_safe_uniqueness_record.rb,
lib/thread_safe_uniqueness_record/version.rb,
lib/thread_safe_uniqueness_record/find_or_create_by.rb

Defined Under Namespace

Classes: Error, FindOrCreateBy, UniquenessValidationError

Constant Summary collapse

MAX_TRIES =
3
ERRORS =
[
  UniquenessValidationError,
  ActiveRecord::RecordNotUnique
].freeze
VERSION =
'0.1.3'.freeze

Class Method Summary collapse

Class Method Details

.with_retry(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/thread_safe_uniqueness_record.rb', line 22

def self.with_retry(&block)
  attempts ||= Concurrent::ThreadLocalVar.new(0)
  block.call
rescue *ERRORS => e
  attempts.value += 1
  raise e if attempts.value >= MAX_TRIES

  retry
end