Sha256: 173ae5f9389a300c627e6fe851d012e19071264159c49d40d79f35694986926c

Contents?: true

Size: 584 Bytes

Versions: 14

Compression:

Stored size: 584 Bytes

Contents

require 'method_object'

module Messaging
  module Adapters
    class Postgres
      class CreateLock
        include MethodObject

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

        def call
          connection.execute "SELECT pg_advisory_lock(#{lock_key});"
        rescue ActiveRecord::QueryCanceled => e
          Messaging.logger.debug "Locking failed, retrying in 5 seconds"
          sleep 5
          retry
        end

        private

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
messaging-4.0.12 lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.11 lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.10 lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.10.pre lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.9 lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.8 lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.7 lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.6 lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.5 lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.4.pre lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.3.pre lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.2.pre lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.1.pre lib/messaging/adapters/postgres/create_lock.rb
messaging-4.0.0.pre lib/messaging/adapters/postgres/create_lock.rb