Sha256: 8edaa3d13e65c554b0715b3c890dba5be457ca0e09df2f7a2cf19ad250452508

Contents?: true

Size: 660 Bytes

Versions: 34

Compression:

Stored size: 660 Bytes

Contents

require 'method_object'

module Messaging
  module Adapters
    class Postgres
      # Creates an advisory lock that is held during the rest of the transaction.
      # If another session is trying to aquire the same lock it will wait until the
      # lock is released.
      # @api private
      class AdvisoryTransactionLock
        include MethodObject

        option :key
        option :connection, default: -> { SerializedMessage.connection }

        def call
          connection.execute "SELECT pg_advisory_xact_lock(#{lock_key});"
        end

        private

        def lock_key
          Zlib.crc32(key)
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
messaging-4.0.12 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.11 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.10 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.10.pre lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.9 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.8 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.7 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.6 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.5 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.4.pre lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.3.pre lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.2.pre lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.1.pre lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-4.0.0.pre lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-3.8.2 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-3.8.1 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-3.8.0 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-3.7.3 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-3.7.2 lib/messaging/adapters/postgres/advisory_transaction_lock.rb
messaging-3.7.1 lib/messaging/adapters/postgres/advisory_transaction_lock.rb