Skip to content

Commit

Permalink
Clean up some duplicated code (puma#2715)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobherrington authored and JuanitoFatas committed Sep 9, 2022
1 parent d4a2967 commit 91ac461
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
10 changes: 0 additions & 10 deletions lib/puma/cluster.rb
Expand Up @@ -164,16 +164,6 @@ def check_workers
].compact.min
end

def wakeup!
return unless @wakeup

begin
@wakeup.write "!" unless @wakeup.closed?
rescue SystemCallError, IOError
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
end
end

def worker(index, master)
@workers = []

Expand Down
10 changes: 0 additions & 10 deletions lib/puma/cluster/worker.rb
Expand Up @@ -168,16 +168,6 @@ def spawn_worker(idx)
@launcher.config.run_hooks :after_worker_fork, idx, @launcher.events
pid
end

def wakeup!
return unless @wakeup

begin
@wakeup.write "!" unless @wakeup.closed?
rescue SystemCallError, IOError
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
end
end
end
end
end
25 changes: 19 additions & 6 deletions lib/puma/runner.rb
Expand Up @@ -15,6 +15,16 @@ def initialize(cli, events)
@app = nil
@control = nil
@started_at = Time.now
@wakeup = nil
end

def wakeup!
return unless @wakeup

@wakeup.write "!" unless @wakeup.closed?

rescue SystemCallError, IOError
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
end

def development?
Expand Down Expand Up @@ -108,19 +118,15 @@ def redirect_io
append = @options[:redirect_append]

if stdout
unless Dir.exist?(File.dirname(stdout))
raise "Cannot redirect STDOUT to #{stdout}"
end
ensure_output_directory_exists(stdout, 'STDOUT')

STDOUT.reopen stdout, (append ? "a" : "w")
STDOUT.puts "=== puma startup: #{Time.now} ==="
STDOUT.flush unless STDOUT.sync
end

if stderr
unless Dir.exist?(File.dirname(stderr))
raise "Cannot redirect STDERR to #{stderr}"
end
ensure_output_directory_exists(stderr, 'STDERR')

STDERR.reopen stderr, (append ? "a" : "w")
STDERR.puts "=== puma startup: #{Time.now} ==="
Expand Down Expand Up @@ -159,5 +165,12 @@ def start_server
server.inherit_binder @launcher.binder
server
end

private
def ensure_output_directory_exists(path, io_name)
unless Dir.exist?(File.dirname(path))
raise "Cannot redirect #{io_name} to #{path}"
end
end
end
end

0 comments on commit 91ac461

Please sign in to comment.