{"repo":"ClosureTree/with_advisory_lock","free":true,"listed":false,"github":"https://github.com/ClosureTree/with_advisory_lock","clone":"git clone https://github.com/ClosureTree/with_advisory_lock.git","description":"Advisory locking for ActiveRecord","language":"Ruby","stars":700,"topics":["advisory-locks","ruby","mysql","mutexes","postgres","activerecord","transaction","postgresql"],"license":null,"category":"databases-storage","readme_excerpt":"with advisory lock Adds advisory locking (mutexes) to ActiveRecord 7.2+, with ruby 3.3+, jruby or truffleruby, when used with MySQL or PostgreSQL. Note: SQLite support has been removed. For single-node SQLite deployments, consider using a Ruby mutex instead. Support for MySQL 5.7 has also been dropped; please use MySQL 8 or PostgreSQL. What's an \"Advisory Lock\"? An advisory lock is a mutex used to ensure no two processes run some process at the same time. When the advisory lock is powered by your database server, your mutex spans hosts. Usage This gem automatically includes the WithAdvisoryLock module in all of your ActiveRecord models. Here's an example of how to use it where User is an ActiveRecord model, and lock name is some string: What happens 1. The thread will wait indefinitely until the lock is acquired. 2. While inside the block, you will exclusively own the advisory lock. 3. The lock will be released after your block ends, even if an exception is raised in the block. Lock wait timeouts with advisory lock takes an options hash as the second parameter. The timeout seconds option defaults to nil , which means wait indefinitely for the lock. A value of zero will try the lock only once. If the lock is acquired, the block will be yielded to. If the lock is currently being held, the block will not be called. Note If a non-nil value is provided for timeout seconds , the block will not be invoked if the lock cannot be acquired within that time-frame. In this case, with advi","default_branch":null,"files":null,"tree":[],"storefront":"/r/ClosureTree","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/ClosureTree/with_advisory_lock/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}