在Gitlab的“ config.ru”中,为什么已经定义了“要求'unicorn'”?

时间:2019-09-15 00:36:14

标签: ruby gitlab rack unicorn

我正在深入研究Gitlab的Web应用程序的工作方式,首先从查看它使用的Web服务器(Unicorn)开始。 config.ru file如下所示:

if defined?(Unicorn)
  require 'unicorn'

  if ENV['RAILS_ENV'] == 'production' || ENV['RAILS_ENV'] == 'staging'
    # Unicorn self-process killer
    require 'unicorn/worker_killer'

    min = (ENV['GITLAB_UNICORN_MEMORY_MIN'] || 400 * 1 << 20).to_i
    max = (ENV['GITLAB_UNICORN_MEMORY_MAX'] || 650 * 1 << 20).to_i

    # Max memory size (RSS) per worker
    use Unicorn::WorkerKiller::Oom, min, max
  end
end

我的问题是,如果已经定义了Unicorn常量,这是否意味着随后的require语句是多余的?如果将if更改为unless,我可以看到这种逻辑是有意义的,但是否则我肯定会丢失一些东西。

我检查了该文件的先前提交,在进行此更改之前,该文件如下所示:

# This file is used by Rack-based servers to start the application.

unless defined?(PhusionPassenger)
  # Unicorn self-process killer
  require 'unicorn/worker_killer'

  # Max memory size (RSS) per worker
  use Unicorn::WorkerKiller::Oom, (200 * (1 << 20)), (250 * (1 << 20))
end

require ::File.expand_path('../config/environment',  __FILE__)

map ENV['RAILS_RELATIVE_URL_ROOT'] || "/" do
  run Gitlab::Application
end

从引入if defined?(Unicorn)require语句的提交中,我了解到if检查是作为unless defined?(PhusionPassenger)的替换而引入的,因为还有许多其他除了独角兽公司外,还有机架式网络服务器。但这并不能弄清楚为什么引入了随后的require语句。

0 个答案:

没有答案
相关问题