简体   繁体   English

如何在开发中关闭PumaWorkerKiller

[英]How to turn off PumaWorkerKiller in development

I am using PumaWorkerKiller using this code in config/puma.rb : 我使用PumaWorkerKiller使用此代码config/puma.rb

  before_fork do
    PumaWorkerKiller.config do |config|
      config.ram           = 512 # mb
    end
    PumaWorkerKiller.start
  end

I want to stop it running on development mode. 我想停止它在开发模式下运行。 I tried to do this by putting a guard clause in like 我试图通过像这样放置一个保护条款来做到这一点

if Rails.env.production?
  # PumaWorkerKiller code goes here
end

This works in development, but triggers an error in production, to the effect that Rails is an unknown constant. 这在开发中有效,但会在生产中引发错误,结果是Rails是一个未知常数。 Presumably it is loading earlier in production than development. 据推测,它在生产中比开发要早加载。

How do I turn off PumaWorkerKiller in development but keep it working in production? 如何在开发中关闭PumaWorkerKiller ,但保持其在生产中正常工作?

Puma should know what environment it is in without referencing rails. Puma应该知道它所处的环境而无需引用rails。

Here's how my config/puma.rb looks, omitting unrelated lines: 这是我的config/puma.rb样子,省略了不相关的行:

environment ENV["RACK_ENV"] || "development"

before_fork do
  require "puma_worker_killer"

  PumaWorkerKiller.config do |config|
    config.ram           = (ENV["PUMA_WORKER_KILLER_RAM"] || 1024).to_i # mb
  end
  PumaWorkerKiller.start unless get(:environment) == "development"
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM