Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Chojnacki <pawel@chojnacki.ws>2017-08-07 20:13:02 +0300
committerRémy Coutable <remy@rymai.me>2017-08-07 20:13:02 +0300
commit746f0ec367a82d83b07d8972fd7043cc10baba23 (patch)
tree2fd525c8ec1c82e60ca2e2100bdc04ebfa16fecf /lib/gitlab/daemon.rb
parentb12107a0b953b566cd58db30ae880800a4a695a6 (diff)
Add sidekiq metrics endpoint and add http server to sidekiq
Diffstat (limited to 'lib/gitlab/daemon.rb')
-rw-r--r--lib/gitlab/daemon.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/gitlab/daemon.rb b/lib/gitlab/daemon.rb
new file mode 100644
index 00000000000..dfd17e35707
--- /dev/null
+++ b/lib/gitlab/daemon.rb
@@ -0,0 +1,62 @@
+module Gitlab
+ class Daemon
+ def self.initialize_instance(*args)
+ raise "#{name} singleton instance already initialized" if @instance
+ @instance = new(*args)
+ Kernel.at_exit(&@instance.method(:stop))
+ @instance
+ end
+
+ def self.instance
+ @instance ||= initialize_instance
+ end
+
+ attr_reader :thread
+
+ def thread?
+ !thread.nil?
+ end
+
+ def initialize
+ @mutex = Mutex.new
+ end
+
+ def enabled?
+ true
+ end
+
+ def start
+ return unless enabled?
+
+ @mutex.synchronize do
+ return thread if thread?
+
+ @thread = Thread.new { start_working }
+ end
+ end
+
+ def stop
+ @mutex.synchronize do
+ return unless thread?
+
+ stop_working
+
+ if thread
+ thread.wakeup if thread.alive?
+ thread.join
+ @thread = nil
+ end
+ end
+ end
+
+ private
+
+ def start_working
+ raise NotImplementedError
+ end
+
+ def stop_working
+ # no-ops
+ end
+ end
+end