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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-22 12:07:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-22 12:07:51 +0300
commit3ad11f24ca52d42694a8ce920a87ead6085d3f85 (patch)
treed5b664aafa7c2b65f470a700431d336d908c0ebc /lib/gitlab/runtime.rb
parent62fcb9ffa9e40db6f34e7dd0d36804d73ef01435 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/runtime.rb')
-rw-r--r--lib/gitlab/runtime.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/gitlab/runtime.rb b/lib/gitlab/runtime.rb
new file mode 100644
index 00000000000..33b7b68e64e
--- /dev/null
+++ b/lib/gitlab/runtime.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+module Gitlab
+ # Provides routines to identify the current runtime as which the application
+ # executes, such as whether it is an application server and which one.
+ module Runtime
+ AmbiguousProcessError = Class.new(StandardError)
+ UnknownProcessError = Class.new(StandardError)
+
+ class << self
+ def identify
+ matches = []
+ matches << :puma if puma?
+ matches << :unicorn if unicorn?
+ matches << :console if console?
+ matches << :sidekiq if sidekiq?
+
+ if matches.one?
+ matches.first
+ elsif matches.none?
+ raise UnknownProcessError.new(
+ "Failed to identify runtime for process #{Process.pid} (#{$0})"
+ )
+ else
+ raise AmbiguousProcessError.new(
+ "Ambiguous runtime #{matches} for process #{Process.pid} (#{$0})"
+ )
+ end
+ end
+
+ def puma?
+ !!defined?(::Puma)
+ end
+
+ # For unicorn, we need to check for actual server instances to avoid false positives.
+ def unicorn?
+ !!(defined?(::Unicorn) && defined?(::Unicorn::HttpServer))
+ end
+
+ def sidekiq?
+ !!(defined?(::Sidekiq) && Sidekiq.server?)
+ end
+
+ def console?
+ !!defined?(::Rails::Console)
+ end
+
+ def web_server?
+ puma? || unicorn?
+ end
+
+ def multi_threaded?
+ puma? || sidekiq?
+ end
+ end
+ end
+end