Class: SvelteOnRails::SsrServerHelpers
- Inherits:
-
Object
- Object
- SvelteOnRails::SsrServerHelpers
- Defined in:
- lib/svelte_on_rails/ssr_server.rb
Defined Under Namespace
Classes: SsrProcess
Instance Attribute Summary collapse
-
#socket_namespace ⇒ Object
readonly
theese helpers are used from the :check rake task For that reason they are within a separate class.
-
#socket_path(ppid: Process.ppid) ⇒ Object
readonly
theese helpers are used from the :check rake task For that reason they are within a separate class.
-
#ssr_server_bin_path ⇒ Object
readonly
theese helpers are used from the :check rake task For that reason they are within a separate class.
Instance Method Summary collapse
- #cleanup_leftover_processes(current_ppid: Process.ppid) ⇒ Object
-
#initialize ⇒ SsrServerHelpers
constructor
A new instance of SsrServerHelpers.
- #leftover_processes(current_ppid: Process.ppid) ⇒ Object
- #leftover_sockets(current_ppid: Process.ppid) ⇒ Object
- #own_processes(current_ppid: Process.ppid) ⇒ Object
- #shutdown(current_ppid: Process.ppid) ⇒ Object
- #ssr_server_ppid_file ⇒ Object
- #start_node_server_command(started_by, ppid: Process.ppid) ⇒ Object
- #start_server_log(start_time, msg) ⇒ Object
Constructor Details
#initialize ⇒ SsrServerHelpers
Returns a new instance of SsrServerHelpers.
337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 337 def initialize @socket_namespace = [ "svelte-ssr", Rails.application.class.module_parent_name[0..30], Rails.env, ].join("-") @ssr_server_bin_path = SvelteOnRails::Configuration.instance.ssr_server_bin_path end |
Instance Attribute Details
#socket_namespace ⇒ Object (readonly)
theese helpers are used from the :check rake task For that reason they are within a separate class
333 334 335 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 333 def socket_namespace @socket_namespace end |
#socket_path(ppid: Process.ppid) ⇒ Object (readonly)
theese helpers are used from the :check rake task For that reason they are within a separate class
333 334 335 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 333 def socket_path @socket_path end |
#ssr_server_bin_path ⇒ Object (readonly)
theese helpers are used from the :check rake task For that reason they are within a separate class
333 334 335 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 333 def ssr_server_bin_path @ssr_server_bin_path end |
Instance Method Details
#cleanup_leftover_processes(current_ppid: Process.ppid) ⇒ Object
394 395 396 397 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 394 def cleanup_leftover_processes(current_ppid: Process.ppid) terminate_processes(leftover_processes(current_ppid: current_ppid), label: "leftover") delete_sockets(leftover_sockets(current_ppid: current_ppid).map { |s| s[:path] }, label: "leftover") end |
#leftover_processes(current_ppid: Process.ppid) ⇒ Object
386 387 388 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 386 def leftover_processes(current_ppid: Process.ppid) scan_processes.reject { |p| p.ppid == current_ppid } end |
#leftover_sockets(current_ppid: Process.ppid) ⇒ Object
390 391 392 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 390 def leftover_sockets(current_ppid: Process.ppid) scan_sockets.reject { |s| s[:ppid] == current_ppid } end |
#own_processes(current_ppid: Process.ppid) ⇒ Object
382 383 384 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 382 def own_processes(current_ppid: Process.ppid) scan_processes.select { |p| p.ppid == current_ppid } end |
#shutdown(current_ppid: Process.ppid) ⇒ Object
399 400 401 402 403 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 399 def shutdown(current_ppid: Process.ppid) terminate_processes(own_processes(current_ppid: current_ppid), label: "own") ensure File.delete(ssr_server_ppid_file) if File.exist?(ssr_server_ppid_file) end |
#ssr_server_ppid_file ⇒ Object
349 350 351 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 349 def ssr_server_ppid_file Rails.root.join("tmp", "pids", 'svelte_on_rails.ppid') end |
#start_node_server_command(started_by, ppid: Process.ppid) ⇒ Object
369 370 371 372 373 374 375 376 377 378 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 369 def start_node_server_command(started_by, ppid: Process.ppid) workers = SvelteOnRails::Configuration.instance.configs[:ssr_server_workers] [ (started_by ? "SVELTE_SSR_SERVER_STARTED_BY=#{started_by}" : nil), SvelteOnRails::Configuration.instance.node_bin_path, @ssr_server_bin_path, socket_path(ppid: ppid), (workers > 1 ? "--workers=#{workers}" : nil) ].compact.join(' ') end |
#start_server_log(start_time, msg) ⇒ Object
405 406 407 408 409 410 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 405 def start_server_log(start_time, msg) line = start_time ? "[SOR] #{msg} (#{((Time.now - start_time) * 1000).round(1)}ms)" : "[SOR] #{msg}" puts line $stdout.flush SvelteOnRails::Lib::Utils.secure_debug_log(line) end |