From a4b504059831764b280a519786d8a5ddcc0d9df0 Mon Sep 17 00:00:00 2001 From: tschafer-gc Date: Fri, 8 Nov 2024 10:01:24 +0000 Subject: [PATCH 1/5] Switch from WEBrick to Puma --- bin/que | 38 +++++++++++--------------------------- que.gemspec | 3 +-- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/bin/que b/bin/que index b38d3f9..353b5b4 100755 --- a/bin/que +++ b/bin/que @@ -4,16 +4,11 @@ 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 "rackup" -end +require "puma" +require "que" +require "rack" $stdout.sync = true @@ -176,25 +171,14 @@ 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 + + Rack::Handler::Puma.run( + app, + Host: host, + Port: options.metrics_port, + Silent: false, + AccessLog: [], + ) end end diff --git a/que.gemspec b/que.gemspec index 2c0b74c..e0e5197 100644 --- a/que.gemspec +++ b/que.gemspec @@ -27,9 +27,8 @@ 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" From 529392fecf816fa201530cbb09037110f2ea41a6 Mon Sep 17 00:00:00 2001 From: tschafer-gc Date: Fri, 8 Nov 2024 22:46:12 +0000 Subject: [PATCH 2/5] Fix imports --- bin/que | 14 +++++++++++++- que.gemspec | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/que b/bin/que index 353b5b4..13e7baf 100755 --- a/bin/que +++ b/bin/que @@ -9,6 +9,11 @@ require "prometheus_gcstat" 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 @@ -172,7 +177,14 @@ if options.metrics_port host = "0.0.0.0" - Rack::Handler::Puma.run( + handler = + if USE_RACKUP + Rackup::Handler::Puma + else + Rack::Handler::Puma + end + + handler.run( app, Host: host, Port: options.metrics_port, diff --git a/que.gemspec b/que.gemspec index e0e5197..bc5ffc5 100644 --- a/que.gemspec +++ b/que.gemspec @@ -29,6 +29,7 @@ Gem::Specification.new do |spec| spec.add_dependency "puma" spec.add_dependency "rack", ">= 2", "< 4" + spec.add_dependency "rackup" spec.add_runtime_dependency "activesupport" spec.metadata["rubygems_mfa_required"] = "true" From 5fcf27403aee34ad877cdad8639351b7ca7ad538 Mon Sep 17 00:00:00 2001 From: tschafer-gc Date: Thu, 14 Nov 2024 09:50:08 +0000 Subject: [PATCH 3/5] Update smoke tests to use both Rack 2 and 3 --- .github/workflows/tests.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5a21a94..c590df7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,6 +24,7 @@ jobs: fail-fast: false matrix: ruby_version: ["3.0", "3.1", "3.2", "3.3"] + rack_version: ["~> 2", "~> 3"] runs-on: ubuntu-latest services: postgres: @@ -51,7 +52,15 @@ jobs: uses: ruby/setup-ruby@v1 with: bundler-cache: true - ruby-version: "${{ matrix.ruby-version }}" + ruby-version: "${{ matrix.ruby_version }}" + - name: Update Gemfile for Rack and Rackup versions + run: | + if [[ "${{ matrix.rack_version }}" == "~> 2" ]]; then + echo 'gem "rackup", "~> 1"' >> Gemfile + fi + echo 'gem "rack", "${{ matrix.rack_version }}"' >> Gemfile + - name: Install Dependencies + run: bundle install - name: Start bin/que run: | bundle exec bin/que ./lib/que.rb --metrics-port=8080 --ci From 51202193d05e508b9eb2758fd0c08dfe5a0092d7 Mon Sep 17 00:00:00 2001 From: tschafer-gc Date: Thu, 14 Nov 2024 11:49:41 +0000 Subject: [PATCH 4/5] Make installations less hacky --- .github/workflows/tests.yml | 11 ++--------- Gemfile | 8 ++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c590df7..e4f976e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: fail-fast: false matrix: ruby_version: ["3.0", "3.1", "3.2", "3.3"] - rack_version: ["~> 2", "~> 3"] + rack_version: ["2.2", "3.1"] runs-on: ubuntu-latest services: postgres: @@ -46,6 +46,7 @@ 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 @@ -53,14 +54,6 @@ jobs: with: bundler-cache: true ruby-version: "${{ matrix.ruby_version }}" - - name: Update Gemfile for Rack and Rackup versions - run: | - if [[ "${{ matrix.rack_version }}" == "~> 2" ]]; then - echo 'gem "rackup", "~> 1"' >> Gemfile - fi - echo 'gem "rack", "${{ matrix.rack_version }}"' >> Gemfile - - name: Install Dependencies - run: bundle install - name: Start bin/que run: | bundle exec bin/que ./lib/que.rb --metrics-port=8080 --ci diff --git a/Gemfile b/Gemfile index 29c8aa4..aea1fbb 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,14 @@ group :test do gem 'rspec', '~> 3.9' end +rack_version = ENV['RACK_VERSION'] || "3.0" +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 + gem 'prometheus-client', '~> 1.0' source "https://rubygems.pkg.github.com/gocardless" do gem "prometheus_gcstat" From a2c331f37f72f21fd488c6f3daef5cf60bf0a6f3 Mon Sep 17 00:00:00 2001 From: tschafer-gc Date: Thu, 14 Nov 2024 12:13:20 +0000 Subject: [PATCH 5/5] Move rack and rackup into dev/test block --- .github/workflows/tests.yml | 2 +- Gemfile | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e4f976e..61ad22a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: fail-fast: false matrix: ruby_version: ["3.0", "3.1", "3.2", "3.3"] - rack_version: ["2.2", "3.1"] + rack_version: ["2.2.5", "3.1"] runs-on: ubuntu-latest services: postgres: diff --git a/Gemfile b/Gemfile index aea1fbb..e735f2d 100644 --- a/Gemfile +++ b/Gemfile @@ -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 @@ -25,14 +33,6 @@ group :test do gem 'rspec', '~> 3.9' end -rack_version = ENV['RACK_VERSION'] || "3.0" -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 - gem 'prometheus-client', '~> 1.0' source "https://rubygems.pkg.github.com/gocardless" do gem "prometheus_gcstat"