Skip to content

Commit

Permalink
Update Gemspec versions (#109)
Browse files Browse the repository at this point in the history
* Update Gemspec versions

There's no reason to block pessimistically (`~>`) to any of these versions. Also add dependencies (bigdecimal) which is warned about in a deprecation warning:

```
/Users/rschneeman/.gem/ruby/3.3.1/gems/get_process_mem-0.2.7/lib/get_process_mem.rb:2: warning: bigdecimal was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.4.0. Add bigdecimal to your Gemfile or gemspec. Also contact author of get_process_mem-0.2.7 to add bigdecimal into its gemspec.
```

* Switch to testing on modern Ruby versions

This doesn't directly mean that these versions won't work, but we no longer make claims about their support.

* Changelog

* Switch to standardrb for linting

* Apply standard linting styles

```
$ be standardrb --fix
standard: Use Ruby Standard Style (https://github.com/standardrb/standard)
  lib/puma_worker_killer/puma_memory.rb:78:20: Style/HashConversion: Prefer ary.to_h to Hash[ary].
standard: Run `standardrb --fix-unsafely` to DANGEROUSLY fix one problem.
```

* Fix uninitialized warning

```
/Users/rschneeman/Documents/projects/puma_worker_killer/puma_worker_killer.gemspec:17: warning: global variable `$INPUT_RECORD_SEPARATOR' not initialized
```
  • Loading branch information
schneems authored Jul 22, 2024
1 parent 83b1d21 commit 0e2275b
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 115 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ jobs:
fail-fast: false
matrix:
ruby:
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- '3.0'
- 3.1
- 3.2
- 3.3
- head
steps:
- name: Checkout code
Expand All @@ -27,8 +23,8 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: rubocop
run: bundle exec rubocop
- name: Ruby linting
run: bundle exec standardrb
- name: test
run: bundle exec rake test
continue-on-error: ${{ matrix.ruby == 'head' }}
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby_version: 3.1
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Main

- Add `bigdecimal` as a dependency (https://github.com/zombocom/puma_worker_killer/pull/109)
- Ruby versions prior to 3.1 may no longer work (https://github.com/zombocom/puma_worker_killer/pull/109)
- Migrate CI from Travis CI to GitHub Actions (#101)
- Update actions/checkout to v4 (#107)

Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

# This is the last version which supports Ruby 2.3
gem 'rubocop', '~> 0.81.0', require: false
gem "standard"
14 changes: 7 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require "bundler/gem_tasks"

require 'rake'
require 'rake/testtask'
require "rake"
require "rake/testtask"

task :default => [:test]
task default: [:test]

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.libs << "lib"
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end
22 changes: 11 additions & 11 deletions lib/puma_worker_killer.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

require 'get_process_mem'
require "get_process_mem"

module PumaWorkerKiller
extend self

attr_accessor :ram, :frequency, :percent_usage, :rolling_restart_frequency,
:rolling_restart_splay_seconds,
:reaper_status_logs, :pre_term, :rolling_pre_term, :on_calculation
:rolling_restart_splay_seconds,
:reaper_status_logs, :pre_term, :rolling_pre_term, :on_calculation

self.ram = 512 # mb
self.frequency = 10 # seconds
self.ram = 512 # mb
self.frequency = 10 # seconds
self.percent_usage = 0.99 # percent of RAM to use
self.rolling_restart_frequency = 6 * 3600 # 6 hours in seconds
self.rolling_restart_splay_seconds = 0.0..300.0 # 0 to 5 minutes in seconds
Expand All @@ -33,15 +33,15 @@ def start(frequency = self.frequency, reaper = self.reaper)
end

def enable_rolling_restart(frequency = rolling_restart_frequency,
splay_seconds = rolling_restart_splay_seconds)
splay_seconds = rolling_restart_splay_seconds)
# Randomize so all workers don't restart at the exact same time across multiple machines.
frequency += rand(splay_seconds)
AutoReap.new(frequency, RollingRestart.new(nil, rolling_pre_term)).start
end
end

require 'puma_worker_killer/puma_memory'
require 'puma_worker_killer/reaper'
require 'puma_worker_killer/rolling_restart'
require 'puma_worker_killer/auto_reap'
require 'puma_worker_killer/version'
require "puma_worker_killer/puma_memory"
require "puma_worker_killer/reaper"
require "puma_worker_killer/rolling_restart"
require "puma_worker_killer/auto_reap"
require "puma_worker_killer/version"
2 changes: 1 addition & 1 deletion lib/puma_worker_killer/auto_reap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module PumaWorkerKiller
class AutoReap
def initialize(timeout, reaper = Reaper.new)
@timeout = timeout # seconds
@reaper = reaper
@reaper = reaper
@running = false
end

Expand Down
8 changes: 4 additions & 4 deletions lib/puma_worker_killer/puma_memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module PumaWorkerKiller
class PumaMemory
def initialize(master = nil)
@master = master || get_master
@master = master || get_master
@workers = nil
end

Expand Down Expand Up @@ -55,7 +55,7 @@ def get_total(workers = set_workers)
worker_memory = workers.values.inject(:+) || 0
worker_memory + master_memory
end
alias get_total_memory get_total
alias_method :get_total_memory, :get_total

def workers
@workers || set_workers
Expand All @@ -71,11 +71,11 @@ def get_master
# sorted by memory ascending (smallest first, largest last)
def set_workers
workers = {}
@master.instance_variable_get('@workers').each do |worker|
@master.instance_variable_get(:@workers).each do |worker|
workers[worker] = GetProcessMem.new(worker.pid).mb
end
if workers.any?
@workers = Hash[workers.sort_by { |_, mem| mem }]
@workers = workers.sort_by { |_, mem| mem }.to_h
else
{}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puma_worker_killer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module PumaWorkerKiller
VERSION = '0.3.1'
VERSION = "0.3.1"
end
42 changes: 22 additions & 20 deletions puma_worker_killer.gemspec
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'puma_worker_killer/version'
require "puma_worker_killer/version"

Gem::Specification.new do |gem|
gem.name = 'puma_worker_killer'
gem.version = PumaWorkerKiller::VERSION
gem.authors = ['Richard Schneeman']
gem.email = ['[email protected]']
gem.description = ' Kills pumas, the code kind '
gem.summary = ' If you have a memory leak in your web code puma_worker_killer can keep it in check. '
gem.homepage = 'https://github.com/schneems/puma_worker_killer'
gem.license = 'MIT'
gem.name = "puma_worker_killer"
gem.version = PumaWorkerKiller::VERSION
gem.authors = ["Richard Schneeman"]
gem.email = ["[email protected]"]
gem.description = " Kills pumas, the code kind "
gem.summary = " If you have a memory leak in your web code puma_worker_killer can keep it in check. "
gem.homepage = "https://github.com/schneems/puma_worker_killer"
gem.license = "MIT"

gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ['lib']
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
gem.require_paths = ["lib"]

gem.add_dependency 'get_process_mem', '~> 0.2'
gem.add_dependency 'puma', '>= 2.7'
gem.add_development_dependency 'rack', '~> 2.0'
gem.add_development_dependency 'rake', '~> 13.0'
gem.add_development_dependency 'test-unit', '>= 0'
gem.add_development_dependency 'wait_for_it', '~> 0.1'
gem.add_dependency "puma", ">= 2.7"
gem.add_dependency "bigdecimal", ">= 2.0"
gem.add_dependency "get_process_mem", ">= 0.2"

gem.add_development_dependency "rack", ">= 3.0"
gem.add_development_dependency "rake", ">= 13.0"
gem.add_development_dependency "rackup", ">= 2.1"
gem.add_development_dependency "test-unit", ">= 0"
gem.add_development_dependency "wait_for_it", ">= 0.1"
end
2 changes: 1 addition & 1 deletion test/fixtures/big.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path('fixture_helper.rb', __dir__)
load File.expand_path("fixture_helper.rb", __dir__)

PumaWorkerKiller.start

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/config/puma_worker_killer_start.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

load File.expand_path('../fixture_helper.rb', __dir__)
load File.expand_path("../fixture_helper.rb", __dir__)

before_fork do
require 'puma_worker_killer'
require "puma_worker_killer"
PumaWorkerKiller.start
end
2 changes: 1 addition & 1 deletion test/fixtures/default.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path('fixture_helper.rb', __dir__)
load File.expand_path("fixture_helper.rb", __dir__)

PumaWorkerKiller.start

Expand Down
16 changes: 8 additions & 8 deletions test/fixtures/fixture_helper.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# frozen_string_literal: true

require 'securerandom'
require "securerandom"

require 'rack'
require 'rack/server'
require "rack"
require "rackup/server"

require 'puma_worker_killer'
require "puma_worker_killer"

PumaWorkerKiller.config do |config|
config.ram = Integer(ENV['PUMA_RAM']) if ENV['PUMA_RAM']
config.frequency = Integer(ENV['PUMA_FREQUENCY']) if ENV['PUMA_FREQUENCY']
config.ram = Integer(ENV["PUMA_RAM"]) if ENV["PUMA_RAM"]
config.frequency = Integer(ENV["PUMA_FREQUENCY"]) if ENV["PUMA_FREQUENCY"]
end

puts "Frequency: #{PumaWorkerKiller.frequency}" if ENV['PUMA_FREQUENCY']
puts "Frequency: #{PumaWorkerKiller.frequency}" if ENV["PUMA_FREQUENCY"]

class HelloWorld
def response(_env)
[200, {}, ['Hello World']]
[200, {}, ["Hello World"]]
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/on_calculation.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path('fixture_helper.rb', __dir__)
load File.expand_path("fixture_helper.rb", __dir__)

PumaWorkerKiller.config do |config|
config.on_calculation = ->(usage) { puts("Current memory footprint: #{usage} mb") }
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/pre_term.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path('fixture_helper.rb', __dir__)
load File.expand_path("fixture_helper.rb", __dir__)

PumaWorkerKiller.config do |config|
config.pre_term = ->(worker) { puts("About to terminate worker: #{worker.inspect}") }
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/rolling_pre_term.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path('fixture_helper.rb', __dir__)
load File.expand_path("fixture_helper.rb", __dir__)

PumaWorkerKiller.config do |config|
config.rolling_pre_term = ->(worker) { puts("About to terminate (rolling) worker: #{worker.pid}") }
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/rolling_restart.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

load File.expand_path('fixture_helper.rb', __dir__)
load File.expand_path("fixture_helper.rb", __dir__)

PumaWorkerKiller.enable_rolling_restart(1, 0..5.0) # 1 second, short 1-5s splay.

Expand Down
Loading

0 comments on commit 0e2275b

Please sign in to comment.