Skip to content

Commit

Permalink
Merge pull request #108 from gocardless/upgrade-rack-webrick
Browse files Browse the repository at this point in the history
Bump rack and webrick versions
  • Loading branch information
stephenbinns authored Aug 7, 2024
2 parents e9db809 + 7ac29ce commit 8519451
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 13 deletions.
43 changes: 41 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,45 @@ jobs:
run: |
bundle exec rubocop --extra-details --display-style-guide --no-server --parallel
smoke_test:
strategy:
fail-fast: false
matrix:
ruby_version: ["3.0", "3.1", "3.2", "3.3"]

runs-on: ubuntu-latest
services:
postgres:
image: postgres:14.2
env:
POSTGRES_DB: que-test
POSTGRES_USER: ubuntu
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 10
env:
PGDATABASE: que-test
PGUSER: ubuntu
PGPASSWORD: password
PGHOST: localhost
BUNDLE_RUBYGEMS__PKG__GITHUB__COM: gocardless-robot-readonly:${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: "${{ matrix.ruby-version }}"
- name: Start bin/que
run: |
bundle exec bin/que ./lib/que.rb --metrics-port=8080 --ci
rspec:
strategy:
fail-fast: false
Expand All @@ -40,7 +79,7 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 10
env:
PGDATABASE: que-test
PGUSER: ubuntu
Expand All @@ -56,4 +95,4 @@ jobs:
ruby-version: "${{ matrix.ruby-version }}"
- name: Run specs
run: |
bundle exec rspec
bundle exec rspec
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.7
3.3.1
59 changes: 51 additions & 8 deletions bin/que
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ 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

$stdout.sync = true

options = OpenStruct.new
Expand Down Expand Up @@ -67,6 +73,10 @@ OptionParser.new do |opts|
$stdout.puts opts
exit 0
end

opts.on("--ci", "Don't wait for sigterm exit after boot") do
options.ci = true
end
end.parse!(ARGV)
# rubocop:enable Layout/LineLength

Expand Down Expand Up @@ -96,6 +106,21 @@ secondary_queues = options.secondary_queues || []

Que.logger ||= Logger.new($stdout)

if options.ci
require "active_record"

ActiveRecord::Base.establish_connection(
adapter: "postgresql",
host: ENV.fetch("PGHOST", "localhost"),
user: ENV.fetch("PGUSER", "postgres"),
password: ENV.fetch("PGPASSWORD", ""),
database: ENV.fetch("PGDATABASE", "que-test"),
)

Que.connection = ActiveRecord
Que.migrate!
end

begin
Que.logger.level = Logger.const_get(log_level.upcase) if log_level
rescue NameError
Expand Down Expand Up @@ -150,15 +175,33 @@ if options.metrics_port
end,
)

Rack::Handler::WEBrick.run(
app,
Host: "0.0.0.0",
Port: options.metrics_port,
Logger: WEBrick::Log.new("/dev/null"),
AccessLog: [],
)
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
end
end

wait_for_signals("INT", "TERM")
# For a basic CI check we just want to ensure the app boots so don't want to
# block the main thread, so this will just exit immediately.
unless options.ci
wait_for_signals("INT", "TERM")
end

worker_group.stop(timeout)
5 changes: 3 additions & 2 deletions que.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +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 "rack", "~> 2.0"
spec.add_dependency "webrick", "~> 1.7"
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

0 comments on commit 8519451

Please sign in to comment.