summaryrefslogtreecommitdiff
path: root/lib/after_commit_queue.rb
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2017-08-17 10:00:31 +0100
committerTiago Botelho <tiagonbotelho@hotmail.com>2017-08-17 10:00:31 +0100
commit21b9e4a36d9485bd802dfed4bc28d0e067b5ccda (patch)
tree8c498449ce547695998f1d2a90ea7f155beac756 /lib/after_commit_queue.rb
parent944ed6a481fa69e92dfe68a9ef28de6087393893 (diff)
downloadgitlab-ce-ee-2628-backport.tar.gz
Backports EE mirror stuck handling feature (https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2628) to CEee-2628-backport
Diffstat (limited to 'lib/after_commit_queue.rb')
-rw-r--r--lib/after_commit_queue.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/after_commit_queue.rb b/lib/after_commit_queue.rb
new file mode 100644
index 00000000000..1e0a9369edc
--- /dev/null
+++ b/lib/after_commit_queue.rb
@@ -0,0 +1,30 @@
+module AfterCommitQueue
+ extend ActiveSupport::Concern
+
+ included do
+ after_commit :_run_after_commit_queue
+ after_rollback :_clear_after_commit_queue
+ end
+
+ def run_after_commit(method = nil, &block)
+ _after_commit_queue = proc { self.send(method) } if method
+ _after_commit_queue << block if block
+ true
+ end
+
+ protected
+
+ def _run_after_commit_queue
+ while action = _after_commit_queue.pop
+ self.instance_eval(&action)
+ end
+ end
+
+ def _after_commit_queue
+ @after_commit_queue ||= []
+ end
+
+ def _clear_after_commit_queue
+ _after_commit_queue.clear
+ end
+end