# How to check if a record lock is in place

**URL:** <https://www.ruby-forum.com/t/how-to-check-if-a-record-lock-is-in-place/170490>\
**Category:** Rails\
**Created:** [June 18, 2009, 3:24am UTC](https://www.ruby-forum.com/t/how-to-check-if-a-record-lock-is-in-place/170490 "2009-06-18T03:24:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Developer\_In\_London](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@Developer\_In\_London](https://www.ruby-forum.com/u/Developer_In_London)\
**Post date:** [June 18, 2009, 3:24am UTC](https://www.ruby-forum.com/t/how-to-check-if-a-record-lock-is-in-place/170490/1 "2009-06-18T03:24:28Z")

</div>

does anyone know how i can check if a record has a lock in place before  
I  
attempt to lock the record?

Eg

# \<-- check here if the specific record is already locked.

# if not locked

MyModel.lock!

# else

# skip to the next model.

thanks

nayeem

---

<div class="post-metadata">

**Author:** ![Developer\_In\_London](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@Developer\_In\_London](https://www.ruby-forum.com/u/Developer_In_London)\
**Post date:** [June 18, 2009, 9:14am UTC](https://www.ruby-forum.com/t/how-to-check-if-a-record-lock-is-in-place/170490/2 "2009-06-18T09:14:31Z")

</div>

2009/6/18 Developer In London [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 

I do not know whether this can be done, but I think that even if it  
could it would not be safe. In the gap between testing the lock and  
attempting to lock it someone else could lock it themselves so you  
would still have to deal with the consequences of attempting to lock  
an already locked record.

Colin
