Sha256: ac93df320aca78847a17b2302c76adf07f69076821308a0ba72c3f86178b49d6

Contents?: true

Size: 780 Bytes

Versions: 4

Compression:

Stored size: 780 Bytes

Contents

# Sometimes you might need a different locking strategy than advisory locks,
# but still use the database-backed storage for idempotent responses. This can arise
# if you are using pgbouncer for instance, where advisory locks are not available
# when using the "transaction mode". You can modify the backend to use a different
# locking mechanism, but keep the rest.

class ActiveRecordBackendWithDistributedLock < Idempo::ActiveRecordBackend
  class LocksViaService
    def acquire(_conn, based_on_str)
      LockingService.acquire("idempo-lk-#{based_on_str}")
    end

    def release(_conn, based_on_str)
      LockingService.release("idempo-lk-#{based_on_str}")
      true
    end
  end

  def lock_implementation_for_connection(_connection)
    LocksViaService.new
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
idempo-1.3.0 examples/custom_locking.rb
idempo-1.2.2 examples/custom_locking.rb
idempo-1.2.1 examples/custom_locking.rb
idempo-1.1.0 examples/custom_locking.rb