Sha256: 9df30ac135dc540a1c302506f0cab8d8f0585caa540aa102f40f8b0fddda2756
Contents?: true
Size: 555 Bytes
Versions: 24
Compression:
Stored size: 555 Bytes
Contents
module WithPgLock ## # Lock PG table, reload model and execute callback if # criterion is met # def with_pg_lock(callback, criterion = proc { true }) # Some notes: # # * nowait is a postgre specific option and may not work with other databases # * nowait will raise an exception if the lock can not be acquired # * we are using a double check lock pattern to reduce lock acquisition with_lock('for update nowait') do reload callback.call if criterion.call end if criterion.call rescue nil end end
Version data entries
24 entries across 24 versions & 1 rubygems