Skip to content

Commit

Permalink
Use events instead of hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Olichwirowicz committed Oct 4, 2021
1 parent 94e7d64 commit 6112487
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lib/puma/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ def bind_to_activated_sockets(bind=true)
@options[:bind_to_activated_sockets] = bind
end

def events(events)
@options[:events] = events
end

# Define the TCP port to bind to. Use +bind+ for more advanced options.
#
# @example
Expand Down Expand Up @@ -596,8 +600,7 @@ def after_worker_fork(&block)
# puts 'After booting...'
# end
def on_booted(&block)
@options[:on_booted] ||= []
@options[:on_booted] << block
@options[:events].on_booted(&block)
end

alias_method :after_worker_boot, :after_worker_fork
Expand Down
4 changes: 4 additions & 0 deletions lib/puma/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def initialize(conf, launcher_args={})
# Advertise the Configuration
Puma.cli_config = @config if defined?(Puma.cli_config)

@config.configure do |user_config, file_config|
file_config.events(@events)
end

@config.load

if @config.options[:bind_to_activated_sockets]
Expand Down
2 changes: 0 additions & 2 deletions lib/puma/single.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ def run
@server = server = start_server
server_thread = server.run

@launcher.config.run_hooks :on_booted, nil, @launcher.events

log "Use Ctrl-C to stop"
redirect_io

Expand Down
4 changes: 0 additions & 4 deletions test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,6 @@ def test_run_hooks_before_fork
assert_run_hooks :before_fork
end

def test_run_hooks_on_booted
assert_run_hooks :on_booted
end

def test_run_hooks_and_exception
conf = Puma::Configuration.new do |c|
c.on_restart do |a|
Expand Down

0 comments on commit 6112487

Please sign in to comment.