Skip to content

Commit e98bbd0

Browse files
author
dhh
committed
Better flow for puma.rb
1 parent a425331 commit e98bbd0

File tree

1 file changed

+11
-12
lines changed
  • railties/lib/rails/generators/rails/app/templates/config

1 file changed

+11
-12
lines changed

railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# are invoked here are part of Puma's configuration DSL. For more information
33
# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
44

5-
rails_env = ENV.fetch("RAILS_ENV", "development")
6-
75
# Puma starts a configurable number of processes (workers) and each process
86
# serves each request in a thread from an internal thread pool.
97
#
@@ -25,7 +23,12 @@ rails_env = ENV.fetch("RAILS_ENV", "development")
2523
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 3 }
2624
threads threads_count, threads_count
2725

28-
if rails_env == "production"
26+
# Specifies the `environment` that Puma will run in.
27+
rails_env = ENV.fetch("RAILS_ENV", "development")
28+
environment rails_env
29+
30+
case rails_env
31+
when "production"
2932
# If you are running more than 1 thread per process, the workers count
3033
# should be equal to the number of processors (CPU cores) in production.
3134
#
@@ -36,21 +39,17 @@ if rails_env == "production"
3639
workers workers_count if workers_count > 1
3740

3841
preload_app!
42+
when "development"
43+
# Specifies a very generous `worker_timeout` so that the worker
44+
# isn't killed by Puma when suspended by a debugger.
45+
worker_timeout 3600
3946
end
4047

4148
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
4249
port ENV.fetch("PORT") { 3000 }
4350

44-
# Specifies the `environment` that Puma will run in.
45-
environment rails_env
46-
4751
# Allow puma to be restarted by `bin/rails restart` command.
4852
plugin :tmp_restart
4953

54+
# Only use a pidfile when requested
5055
pidfile ENV["PIDFILE"] if ENV["PIDFILE"]
51-
52-
if rails_env == "development"
53-
# Specifies a very generous `worker_timeout` so that the worker
54-
# isn't killed by Puma when suspended by a debugger.
55-
worker_timeout 3600
56-
end

0 commit comments

Comments
 (0)