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 13:38:05 +0100
commitf865b1b459b7c53eb57580246d8e20c4fd45f7fe (patch)
treeb2a6c92cbc4187ca2ed86859ad280990b2525019 /lib/after_commit_queue.rb
parent4a2a6d521a260981482ee8e4931ebf06cb4f5b6a (diff)
downloadgitlab-ce-f865b1b459b7c53eb57580246d8e20c4fd45f7fe.tar.gz
Backports EE mirror stuck handling feature (https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2628) to CEee-2628-backport-to-ce
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..b67575a3ac2
--- /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