Module: LogStruct::Integrations::Puma::RackHandlerPatch
- Extended by:
- T::Sig
- Defined in:
- lib/log_struct/integrations/puma.rb
Overview
Hook Rack::Handler::Puma.run to emit structured started/shutdown
Instance Method Summary collapse
Instance Method Details
#run(app, *args, &block) ⇒ T.untyped
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/log_struct/integrations/puma.rb', line 458 def run(app, *args, &block) rest = args = T.let({}, T::Hash[T.untyped, T.untyped]) rest.each do |value| next unless value.is_a?(Hash) .merge!(value) end begin si = T.cast(::LogStruct::Integrations::Puma::STATE[:start_info], T::Hash[Symbol, T.untyped]) si[:mode] ||= "single" si[:environment] ||= ((defined?(::Rails) && ::Rails.respond_to?(:env)) ? ::Rails.env : nil) si[:pid] ||= Process.pid si[:listening] ||= [] port = T.let(nil, T.untyped) host = T.let(nil, T.untyped) if .respond_to?(:[]) port = [:Port] || ["Port"] || [:port] || ["port"] host = [:Host] || ["Host"] || [:host] || ["host"] end if port list = T.cast(si[:listening], T::Array[T.untyped]) list.clear h = (host && host != "0.0.0.0") ? host : "127.0.0.1" list << "tcp://#{h}:#{port}" end state = ::LogStruct::Integrations::Puma::STATE state[:handler_pending_started] = true unless state[:started_emitted] rescue => e ::LogStruct::Integrations::Puma.handle_integration_error(e) end begin Kernel.at_exit do unless ::LogStruct::Integrations::Puma::STATE[:shutdown_emitted] ::LogStruct::Integrations::Puma.emit_shutdown!("Exiting") ::LogStruct::Integrations::Puma::STATE[:shutdown_emitted] = true end rescue => e ::LogStruct::Integrations::Puma.handle_integration_error(e) end rescue => e ::LogStruct::Integrations::Puma.handle_integration_error(e) end begin result = super(app, **, &block) ensure state = ::LogStruct::Integrations::Puma::STATE if state[:handler_pending_started] && !state[:started_emitted] begin ::LogStruct::Integrations::Puma.emit_started! state[:started_emitted] = true rescue => e ::LogStruct::Integrations::Puma.handle_integration_error(e) ensure state[:handler_pending_started] = false end end end result end |