Skip to content

Commit

Permalink
Merge pull request #19 from babbel/puma-6-compatibility
Browse files Browse the repository at this point in the history
Puma 6 compatibility
  • Loading branch information
amrrbakry authored Dec 23, 2022
2 parents 25ed729 + ecfbf63 commit 30537c8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.2]

- Add Puma 6 compatibility
## [1.1.1]

Public release.
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PATH
remote: .
specs:
puma-plugin-telemetry (1.1.1)
puma (>= 5.0)
puma-plugin-telemetry (1.1.2)
puma (< 7)

GEM
remote: https://rubygems.org/
Expand All @@ -14,7 +14,7 @@ GEM
parallel (1.22.1)
parser (3.1.2.0)
ast (~> 2.4.1)
puma (5.6.4)
puma (6.0.1)
nio4r (~> 2.0)
rack (2.2.3.1)
rainbow (3.1.1)
Expand Down Expand Up @@ -64,4 +64,4 @@ DEPENDENCIES
rubocop-performance (~> 1.9)

BUNDLED WITH
2.1.4
2.3.12
21 changes: 16 additions & 5 deletions lib/puma/plugin/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ def socket_telemetry(telemetry, launcher)
#
module PluginInstanceMethods
def start(launcher)
@launcher = launcher

unless Puma::Plugin::Telemetry.config.enabled?
launcher.events.log 'plugin=telemetry msg="disabled, exiting..."'
log_writer.log 'plugin=telemetry msg="disabled, exiting..."'
return
end

@launcher = launcher
@launcher.events.log 'plugin=telemetry msg="enabled, setting up runner..."'
log_writer.log 'plugin=telemetry msg="enabled, setting up runner..."'

in_background do
sleep Puma::Plugin::Telemetry.config.initial_delay
Expand All @@ -79,13 +80,13 @@ def start(launcher)

def run!
loop do
@launcher.events.debug 'plugin=telemetry msg="publish"'
log_writer.debug 'plugin=telemetry msg="publish"'

call(Puma::Plugin::Telemetry.build(@launcher))
rescue Errno::EPIPE
# Occurs when trying to output to STDOUT while puma is shutting down
rescue StandardError => e
@launcher.events.error "plugin=telemetry err=#{e.class} msg=#{e.message.inspect}"
log_writer.error "plugin=telemetry err=#{e.class} msg=#{e.message.inspect}"
ensure
sleep Puma::Plugin::Telemetry.config.frequency
end
Expand All @@ -96,6 +97,16 @@ def call(telemetry)
target.call(telemetry)
end
end

private

def log_writer
if Puma::Const::PUMA_VERSION.to_i < 6
@launcher.events
else
@launcher.log_writer
end
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/plugin/telemetry/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Puma
class Plugin
module Telemetry
VERSION = '1.1.1'
VERSION = '1.1.2'
end
end
end
2 changes: 1 addition & 1 deletion puma-plugin-telemetry.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'puma', '>= 5.0'
spec.add_dependency 'puma', '< 7'
end

0 comments on commit 30537c8

Please sign in to comment.