ruby - rails block a record for change for another places in the code -


i have ruby on rails application lot of sidekiq workers. of workers can work while (at least few minutes).

how can block record changes places (ie controllers), avoid data conflict when save record in worker?

you need lock model:

account = account.first  account.with_lock   # block called within transaction,   # account locked.   account.balance -= 100   account.save! end 

you can read more here.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -