class Assignment def transfer(person_id: nil, attempt: 0) random = false if !person_id person_id = get_random_person.id random = true end @thing.update(assignee: person_id) rescue NotFound raise 'Person not found' if !random attempt += 1 raise if attempt > 3 new_person = get_random_person(refresh: true) transfer( person_id: new_person.id, attempt: attempt ) end private def get_random_person(refresh: false) @person = nil if refresh @person ||= begin RandomPerson.new end end end