lib/ledgerizer/extensions/locking_extensions.rb
def retry_deadlocks
      # Error examples:
      #   PG::Error: ERROR:  deadlock detected
      #   Mysql::Error: Deadlock found when trying to get lock
      yield
    rescue ActiveRecord::StatementInvalid, ActiveRecord::RecordNotUnique => e
      if e.message =~ /deadlock/i || e.message =~ /database is locked/i
        # Somebody else is in the midst of creating the record. We'd better
        # retry, so we ensure they're done before we move on.
        ActiveSupport::Notifications.publish('deadlock_retry.ledgerizer', exception: e)

        retry
      else
        raise
      end
    end
# Execute the given block within a database transaction, and retry the
# transaction from the beginning if a RestartTransaction exception is raised.
Execute the given block within a database transaction, and retry the
transaction from the beginning if a RestartTransaction exception is raised.
Execute the given block within a database transaction and retry the transaction from the beginning if a RestartTransaction exception is raised .
def retry_deadlocks
      yield
    rescue ActiveRecord::StatementInvalid, ActiveRecord::RecordNotUnique => e
      if e.message =~ /deadlock/i || e.message =~ /database is locked/i
        ActiveSupport::Notifications.publish('deadlock_retry.ledgerizer', exception: e)
        retry
      else
        raise
      end
    end
def retry_deadlocks yield rescue ActiveRecord :: StatementInvalid , ActiveRecord :: RecordNotUnique => e if e . message =~ / deadlock /i || e . message =~ / database is locked /i ActiveSupport :: Notifications . publish ( 'deadlock_retry.ledgerizer' , exception : e ) retry else raise end end
Execute the given block within a database transaction, and retry the
transaction from the beginning if a RestartTransaction exception is raised.
Execute the given block within a database transaction and retry the transaction from the beginning if a RestartTransaction exception is raised .
# Error examples: #   PG::Error: ERROR:  deadlock detected #   Mysql::Error: Deadlock found when trying to get lock # Somebody else is in the midst of creating the record. We'd better # retry, so we ensure they're done before we move on.