Skip to content

Commit

Permalink
Load JSON at runtime
Browse files Browse the repository at this point in the history
Closes puma#2206
  • Loading branch information
MSP-Greg committed May 17, 2020
1 parent 91e57f4 commit 622f3fb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/puma.rb
Expand Up @@ -20,6 +20,7 @@ def self.stats_object=(val)
end

def self.stats
require 'json'
@get_stats.stats.to_json
end

Expand Down
6 changes: 4 additions & 2 deletions lib/puma/app/status.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'json'

module Puma
module App
# Check out {#call}'s source code to see what actions this web application
Expand All @@ -19,6 +17,10 @@ def call(env)
return rack_response(403, 'Invalid auth token', 'text/plain')
end

if env['PATH_INFO'] =~ /\/(gc-stats|stats|thread-backtraces)$/
require 'json'
end

case env['PATH_INFO']
when /\/stop$/
@cli.stop
Expand Down
3 changes: 2 additions & 1 deletion lib/puma/cluster.rb
Expand Up @@ -5,7 +5,6 @@
require 'puma/plugin'

require 'time'
require 'json'

module Puma
# This class is instantiated by the `Puma::Launcher` and used
Expand Down Expand Up @@ -95,6 +94,7 @@ def term?

def ping!(status)
@last_checkin = Time.now
require 'json'
@last_status = JSON.parse(status, symbolize_names: true)
end

Expand Down Expand Up @@ -330,6 +330,7 @@ def worker(index, master)
while true
sleep Const::WORKER_CHECK_INTERVAL
begin
require 'json'
io << "p#{Process.pid}#{server.stats.to_json}\n"
rescue IOError
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
Expand Down

0 comments on commit 622f3fb

Please sign in to comment.