From 5d7ee7a1b6c818dd0ccba6a393875072dabd7eba Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 20 Oct 2016 09:33:44 +0200 Subject: Use optimistic locking --- lib/gitlab/optimistic_locking.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 lib/gitlab/optimistic_locking.rb (limited to 'lib') diff --git a/lib/gitlab/optimistic_locking.rb b/lib/gitlab/optimistic_locking.rb new file mode 100644 index 00000000000..7668c518bc5 --- /dev/null +++ b/lib/gitlab/optimistic_locking.rb @@ -0,0 +1,13 @@ +module Gitlab + module OptimisticLocking + def retry_lock(subject, &block) + while true do + begin + return yield subject + rescue StaleObjectError + subject.reload + end + end + end + end +end -- cgit v1.2.1