solid_queue: Jobs and transactional integrity docs don't seem to be what actually happens in Solid Queue when using a single DB
Having your jobs in the same ACID-compliant database as your application data enables a powerful yet sharp tool: taking advantage of transactional integrity to ensure some action in your app is not committed unless your job is also committed and viceversa, and ensuring that your job won’t be enqueued until the transaction within which you’re enqueuing it is committed.
The above text seems to indicate that if you use the same DB for ActiveRecord application models and the Solid Queue models, job enqueuing will only happen if the application model changes are successfully committed to the DB & vice versa.
We changed our implementation to move from a separate DB to a single DB to avail of this. But in practice, we are seeing that this is not the case.
After we installed some debuggers, we found that eventually, this line of code is hit. That rails method creates a new nested transaction.
Such nested transactions will not roll back all transactions correctly when using something like postgres. We confirmed this behaviour by explicitly rolling back the application transaction after enqueuing the job. The Job record was saved, the application model record was not.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (7 by maintainers)
Commits related to this issue
- Do not create a new transaction when creating a ReadyExecution Fixes https://github.com/rails/solid_queue/issues/421 — committed to leondmello/solid_queue by leondmello 2 years ago
Aha, thanks a lot for creating that. The reason this is happening is that you’re explicitly using a different connection pool for Solid Queue, as described in the README as an alternative way to not have this transactional behaviour with jobs:
If I do this change in your repo, to ensure the same connection pool is used by
SolidQueue::RecordandApplicationRecord:The behaviour is what you expect and what’s documented: