简体   繁体   中英

Sidekiq background job rollback when fail

I want to know if a sidekiq background job will rollback its database if the job fail to finish? ie machine died or something like that.

I'm using rails 4.2.1, sidekiq 4.0.1

Sidekiq doesn't really handle transactions, but Rails does. So if you have several statements you should wrap them in a transaction ie:

ActiveRecord::Base.transaction do
  User.update(amount: 100)
  Bank.update(amount: 0)
end

Then, if something goes wrong, these changes will be rolled back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM