How to apply lock on particular column in ruby on rails? -
how apply lock on particular field same number not generate again.
i have created algoritham in create string using year+000..+integer number example : "20150001","20150002","20150003" etc.
the problem when multiple user request number @ time same number generated.
following function call
def get_algo_number(model_name,prefix) <br> year = get_year if model_name.count > 0 last_number = model_name.last.number if last_number[2..5].to_i > year.to_i return create_number(year,prefix) else # if letest generated number exist generate new number return last_number.next end else return create_number(year,prefix) end end
please if have solution regarding apply lock. thanks
yes, resolved problem using multi-threading.
Comments
Post a Comment