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
Post a Comment