Skip to content

Commit

Permalink
Clean up some duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobherrington committed Sep 25, 2021
1 parent e2815b6 commit c47a836
Show file tree
Hide file tree
Showing 3 changed files with 21 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
27 changes: 21 additions & 6 deletions lib/puma/runner.rb
Expand Up @@ -15,6 +15,17 @@ def initialize(cli, events)
@app = nil
@control = nil
@started_at = Time.now
@wakeup = nil
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 development?
Expand Down Expand Up @@ -108,19 +119,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.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.reopen stderr, (append ? "a" : "w")
STDERR.puts "=== puma startup: #{Time.now} ==="
Expand Down Expand Up @@ -159,5 +166,13 @@ def start_server
server.inherit_binder @launcher.binder
server
end

private

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

0 comments on commit c47a836

Please sign in to comment.