Forum: Ruby on Rails AcriveRecord (2.2.0) after_update callback and database transaction

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6bf9328eef0afadd9c9d05334f8dd42b?d=identicon&s=25 Hubert Łępicki (Guest)
on 2008-11-06 14:04
(Received via mailing list)
Hi,

Does anyone know how can I execute some bit of code after transaction
wrapping up activerecord update/save methods completed?

after_update and after_save filters are both wrapped into the same
transaction, and I need to make external service (druby) aware of
changes immediately after changes were made. Now - I use separate
thread and sleep(1) in druby service to make it see changes, but it's
not good enough solution. Any ideas how can do it?

Thanks,
Hubert
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2008-11-10 10:16
(Received via mailing list)
Hubert £êpicki wrote:

> Does anyone know how can I execute some bit of code after transaction
> wrapping up activerecord update/save methods completed?
>
> after_update and after_save filters are both wrapped into the same
> transaction, and I need to make external service (druby) aware of
> changes immediately after changes were made. Now - I use separate
> thread and sleep(1) in druby service to make it see changes, but it's
> not good enough solution. Any ideas how can do it?

Like you, I've used the sleep hack, because ActiveRecord
doesn't currently have after_commit callbacks.

The only other solution would be to move the remote
call to your controller, after the transaction block
or save call.  You can still leave the details of the
remote call in the model, but just call it from the controller.

--
Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com
This topic is locked and can not be replied to.