Skip to content

Commit 9ce92d9

Browse files
authored
Merge pull request #124 from fly-apps/solid_queue_in_puma
Solid queue in puma
2 parents 48813c4 + ff53b03 commit 9ce92d9

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

lib/generators/dockerfile_generator.rb

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def generate_app
336336
force: File.exist?("fly.toml")
337337
end
338338

339-
if using_solidq? && deploy_database == "sqlite3" && File.exist?("config/puma.rb")
339+
if solidq_launcher == :puma && !File.read("config/puma.rb").include?(":solid_queue")
340340
append_to_file "config/puma.rb", "\n# Run the Solid Queue's supervisor\nplugin :solid_queue\n"
341341
end
342342

@@ -431,6 +431,10 @@ def generate_app
431431
env["HTTP_PORT"] = "8080"
432432
end
433433

434+
if solidq_launcher == :env && !dockerfile.include?("SOLID_QUEUE_IN_PUMA")
435+
env["SOLID_QUEUE_IN_PUMA"] = "true"
436+
end
437+
434438
unless env.empty?
435439
toml = IO.read("fly.toml")
436440
if !toml.include?("[[env]]")
@@ -550,6 +554,22 @@ def using_solidq?
550554
@gemfile.include?("solid_queue") and includes_jobs?
551555
end
552556

557+
def solidq_launcher
558+
if !using_solidq?
559+
:none
560+
elsif deploy_database != "sqlite3"
561+
:process
562+
elsif File.exist? "config/puma.rb"
563+
if File.read("config/puma.rb").include?("SOLID_QUEUE_IN_PUMA")
564+
File.exist?("fly.toml") ? :env : :none
565+
else
566+
:puma
567+
end
568+
else
569+
:procfile
570+
end
571+
end
572+
553573
def parallel?
554574
(using_node? || using_bun?) && options.parallel
555575
end
@@ -990,6 +1010,10 @@ def deploy_env
9901010
env.merge! @@args["deploy"].to_h { |key, value| [key, "$#{key}"] }
9911011
end
9921012

1013+
if solidq_launcher == :env
1014+
env["SOLID_QUEUE_IN_PUMA"] = "true"
1015+
end
1016+
9931017
env.merge! @@vars["deploy"] if @@vars["deploy"]
9941018

9951019
env.map { |key, value| "#{key}=#{value.inspect}" }.sort
@@ -1216,23 +1240,29 @@ def dbprep_command
12161240

12171241
def procfile
12181242
if using_passenger?
1219-
{
1243+
base = {
12201244
nginx: "nginx"
12211245
}
12221246
elsif options.nginx?
1223-
{
1247+
base = {
12241248
nginx: '/usr/sbin/nginx -g "daemon off;"',
12251249
rails: "./bin/rails server -p 3001"
12261250
}
12271251
elsif using_thruster?
1228-
{
1252+
base = {
12291253
rails: "bundle exec thrust ./bin/rails server"
12301254
}
12311255
else
1232-
{
1256+
base = {
12331257
rails: "./bin/rails server"
12341258
}
12351259
end
1260+
1261+
if solidq_launcher == :procfile
1262+
base["solidq"] = "bundle exec rake solid_queue:start"
1263+
end
1264+
1265+
base
12361266
end
12371267

12381268
def using_thruster?

test/results/solid_queue_sqlite3/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ RUN groupadd --system --gid 1000 rails && \
6161
USER 1000:1000
6262

6363
# Deployment options
64-
ENV DATABASE_URL="sqlite3:///data/production.sqlite3"
64+
ENV DATABASE_URL="sqlite3:///data/production.sqlite3" \
65+
SOLID_QUEUE_IN_PUMA="true"
6566

6667
# Entrypoint prepares the database.
6768
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

test/results/solid_queue_sqlite3/puma.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,3 @@
3939
# Specify the PID file. Defaults to tmp/pids/server.pid in development.
4040
# In other environments, only set the PID file if requested.
4141
pidfile ENV["PIDFILE"] if ENV["PIDFILE"]
42-
43-
# Run the Solid Queue's supervisor
44-
plugin :solid_queue

0 commit comments

Comments
 (0)