# After\_update woes

**URL:** <https://www.ruby-forum.com/t/after-update-woes/129475>\
**Category:** Rails\
**Created:** [February 18, 2008, 10:53pm UTC](https://www.ruby-forum.com/t/after-update-woes/129475 "2008-02-18T22:53:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [February 18, 2008, 10:53pm UTC](https://www.ruby-forum.com/t/after-update-woes/129475/1 "2008-02-18T22:53:05Z")

</div>

Hey everyone.

I am trying to run a an external process after a update from the view.  
I currently have it set up to run after\_update but it seems that the  
transaction it uses hasn’t been closed at that point. My process is  
supposed to check some variables in the database and change a specific  
column in the database. Now because the transaction hasn’t been closed  
it results in a deadlock. Does any one have a good work around to  
achieve this?

---

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [February 18, 2008, 11:09pm UTC](https://www.ruby-forum.com/t/after-update-woes/129475/2 "2008-02-18T23:09:42Z")

</div>

InnerSparkMedia wrote:

> I am trying to run a an external process after a update from the view.  
> I currently have it set up to run after\_update but it seems that the  
> transaction it uses hasn’t been closed at that point. My process is  
> supposed to check some variables in the database and change a specific  
> column in the database. Now because the transaction hasn’t been closed  
> it results in a deadlock. Does any one have a good work around to  
> achieve this?

One hack is to put something like “sleep 2” at the beginning of the  
external process. Or call the external process from your controller.  
Or change the transaction visibility level of your external-process  
DB connection.

But it’d be nice if transaction calls could again take model instance  
parameters, allowing implementation of an after\_commit callback.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [February 18, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/after-update-woes/129475/3 "2008-02-18T23:17:59Z")

</div>

How do you go about calling say a model method from the controller?  
Because my call to the external process is defined in the model.

---

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [February 18, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/after-update-woes/129475/4 "2008-02-18T23:19:44Z")

</div>

Also when dose a transaction end?

On Feb 18, 3:16 pm, InnerSparkMedia

---

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [February 18, 2008, 11:18pm UTC](https://www.ruby-forum.com/t/after-update-woes/129475/5 "2008-02-18T23:18:34Z")

</div>

or just the external process?

On Feb 18, 3:16 pm, InnerSparkMedia

---

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [February 18, 2008, 11:39pm UTC](https://www.ruby-forum.com/t/after-update-woes/129475/6 "2008-02-18T23:39:13Z")

</div>

InnerSparkMedia wrote:

> Also when dose a transaction end?

You can put your call to the external process after the  
end of the transaction “do” block (or after the save for  
automatic transaction wrappings).

Just call Model.method if the process can be started by a  
class method of Model.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [February 18, 2008, 11:48pm UTC](https://www.ruby-forum.com/t/after-update-woes/129475/7 "2008-02-18T23:48:39Z")

</div>

Thank you for your help. They did it. What I had to do was place  
@model.method in the if saved statement and it worked.
