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 Sep 23, 2021
1 parent 94e7d64 commit f0304fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 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

0 comments on commit f0304fb

Please sign in to comment.