Search code examples
ruby-on-railsactiverecordtransactions

Can I have a way to save a record in the after_rollback model callback?


The basic usecase is that I need to log that something has occurred, even if in my code an error occurred and the whole transaction is to be aborted.

For a variety of reasons it would be extremely convenient to not have to manually handle partial rollbacks via nested transactions. And my basic fallback is to log this information via a message queue and have that queue save records to the database.

My question is, is there a way to allow me to save a model even if I know the current transaction is being rolled back? Or is event publishing pretty much the only way?


Solution

  • Since I could not find any other ideas, the solution I went with is to throw these messages on a background processing queue and just rollback, and have background workers log this information.