Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from WEBrick to Puma #114

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
fail-fast: false
matrix:
ruby_version: ["3.0", "3.1", "3.2", "3.3"]
rack_version: ["2.2.5", "3.1"]
runs-on: ubuntu-latest
services:
postgres:
Expand All @@ -45,13 +46,14 @@ jobs:
PGPASSWORD: password
PGHOST: localhost
BUNDLE_RUBYGEMS__PKG__GITHUB__COM: gocardless-robot-readonly:${{ secrets.GITHUB_TOKEN }}
RACK_VERSION: "${{ matrix.rack_version }}"
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: "${{ matrix.ruby-version }}"
ruby-version: "${{ matrix.ruby_version }}"
- name: Start bin/que
run: |
bundle exec bin/que ./lib/que.rb --metrics-port=8080 --ci
Expand Down
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ group :development, :test do
gem 'rubocop-rspec', '~> 3.0.2'
gem 'rubocop-sequel', '~> 0.3.4'
gem 'sequel', require: nil

rack_version = ENV.fetch('RACK_VERSION', "3.1")
gem "rack", rack_version
if Gem::Version.new(rack_version) < Gem::Version.new('3.0.0')
gem "rackup", "~> 1.0"
else
gem "rackup", "~> 2.0"
end
end

group :test do
Expand Down
49 changes: 24 additions & 25 deletions bin/que
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
require "logger"
require "optparse"
require "ostruct"
require "que"
require "rack"
require "prometheus/middleware/exporter"
require "prometheus_gcstat"
require "webrick"

if Rack.release[0] == "3"
# Required if using Rack 3.x
require "puma"
require "que"
require "rack"
USE_RACKUP = Rack.release.split(".")[0].to_i >= 3
if USE_RACKUP
require "rackup"
end
require "rack/handler/puma"

$stdout.sync = true

Expand Down Expand Up @@ -176,25 +176,24 @@ if options.metrics_port
)

host = "0.0.0.0"
logger = WEBrick::Log.new("/dev/null")

if Rack.release[0] == "3"
Rackup::Handler::WEBrick.run(
app,
Host: host,
Port: options.metrics_port,
Logger: logger,
AccessLog: [],
)
else
Rack::Handler::WEBrick.run(
app,
Host: host,
Port: options.metrics_port,
Logger: logger,
AccessLog: [],
)
end

handler =
if USE_RACKUP
Rackup::Handler::Puma
else
Rack::Handler::Puma
end

pidfile_opts = Dir.exist?("./tmp/pids/") ? {} : { pidfile: nil }

handler.run(
app,
Host: host,
Port: options.metrics_port,
Silent: false,
AccessLog: [],
**pidfile_opts,
)
end
end

Expand Down
2 changes: 1 addition & 1 deletion que.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Gem::Specification.new do |spec|
# This is highly non ideal, but unless we properly fork, we have to do this for now.
spec.add_dependency "prometheus-client"

spec.add_dependency "puma"
spec.add_dependency "rack", ">= 2", "< 4"
spec.add_dependency "rackup"
spec.add_dependency "webrick"

spec.add_runtime_dependency "activesupport"
spec.metadata["rubygems_mfa_required"] = "true"
Expand Down
Loading