79643893

Date: 2025-05-29 12:28:32
Score: 1
Natty:
Report link

I find the easiest way to make thread safe changes is to an ActiveRecord object is to use .with_lock

Your code might look like...

def change_occupied_spaces!(by:)
    retries ||= 0

    self.with_lock do
      reload
      new_value = occupied_spaces + by

      if new_value < 0
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: psugirlinpa