Skip to content

Commit

Permalink
Set SOLID_QUEUE_IN_PUMA if present
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Nov 4, 2024
1 parent a216562 commit ff53b03
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
40 changes: 35 additions & 5 deletions lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def generate_app
force: File.exist?("fly.toml")
end

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

Expand Down Expand Up @@ -431,6 +431,10 @@ def generate_app
env["HTTP_PORT"] = "8080"
end

if solidq_launcher == :env && !dockerfile.include?("SOLID_QUEUE_IN_PUMA")
env["SOLID_QUEUE_IN_PUMA"] = "true"
end

unless env.empty?
toml = IO.read("fly.toml")
if !toml.include?("[[env]]")
Expand Down Expand Up @@ -550,6 +554,22 @@ def using_solidq?
@gemfile.include?("solid_queue") and includes_jobs?
end

def solidq_launcher
if !using_solidq?
:none
elsif deploy_database != "sqlite3"
:process
elsif File.exist? "config/puma.rb"
if File.read("config/puma.rb").include?("SOLID_QUEUE_IN_PUMA")
File.exist?("fly.toml") ? :env : :none
else
:puma
end
else
:procfile
end
end

def parallel?
(using_node? || using_bun?) && options.parallel
end
Expand Down Expand Up @@ -990,6 +1010,10 @@ def deploy_env
env.merge! @@args["deploy"].to_h { |key, value| [key, "$#{key}"] }
end

if solidq_launcher == :env
env["SOLID_QUEUE_IN_PUMA"] = "true"
end

env.merge! @@vars["deploy"] if @@vars["deploy"]

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

def procfile
if using_passenger?
{
base = {
nginx: "nginx"
}
elsif options.nginx?
{
base = {
nginx: '/usr/sbin/nginx -g "daemon off;"',
rails: "./bin/rails server -p 3001"
}
elsif using_thruster?
{
base = {
rails: "bundle exec thrust ./bin/rails server"
}
else
{
base = {
rails: "./bin/rails server"
}
end

if solidq_launcher == :procfile
base["solidq"] = "bundle exec rake solid_queue:start"
end

base
end

def using_thruster?
Expand Down
3 changes: 2 additions & 1 deletion test/results/solid_queue_sqlite3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ RUN groupadd --system --gid 1000 rails && \
USER 1000:1000

# Deployment options
ENV DATABASE_URL="sqlite3:///data/production.sqlite3"
ENV DATABASE_URL="sqlite3:///data/production.sqlite3" \
SOLID_QUEUE_IN_PUMA="true"

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
Expand Down
3 changes: 0 additions & 3 deletions test/results/solid_queue_sqlite3/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,3 @@
# Specify the PID file. Defaults to tmp/pids/server.pid in development.
# In other environments, only set the PID file if requested.
pidfile ENV["PIDFILE"] if ENV["PIDFILE"]

# Run the Solid Queue's supervisor
plugin :solid_queue

0 comments on commit ff53b03

Please sign in to comment.