Do sidekiq jobs run inside a large transaction?

2.4k views Asked by At

I have a large record import job running on our web application. The import is run by a PORO which calculates how many objects it needs to import and divides the number by an index of the current object it is presently on, leaving me with a clean way to calculate the percentage complete. After it does this calculation I am saving this percentage to the database in order to poll it and let the user know how far along this import has come.

It doesn't appear that sidekiq allows for these database writes to touch the database until the entire job is over, leaving me with this quesiton:

Is every sidekiq job wrapped entirely in a transaction?

(I'm not lazy I just don't have a lot of time to go through the code and discover this myself.)

2

There are 2 answers

0
ancoanco On BEST ANSWER

No, Sidekiq does not inherently wrap it's jobs in a transaction. Ensure you don't have your loop, or the method calling your loop, wrapped in a transaction.

0
Mike Perham On

No. You control the DB transactional boundaries within the perform method using Model.transaction { }. Sidekiq never touches the database.