Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up some duplicated code #2715

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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