Class: SvelteOnRails::SsrServerHelpers
- Inherits:
-
Object
- Object
- SvelteOnRails::SsrServerHelpers
- Defined in:
- lib/svelte_on_rails/ssr_client.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, caller: '') ⇒ Object
- #ssr_client_ppid_file ⇒ Object
- #start_node_server_command(started_by, ppid: Process.ppid) ⇒ Object
Constructor Details
#initialize ⇒ SsrServerHelpers
Returns a new instance of SsrServerHelpers.
339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 339 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
335 336 337 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 335 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
335 336 337 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 335 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
335 336 337 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 335 def ssr_server_bin_path @ssr_server_bin_path end |
Instance Method Details
#cleanup_leftover_processes(current_ppid: Process.ppid) ⇒ Object
396 397 398 399 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 396 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
388 389 390 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 388 def leftover_processes(current_ppid: Process.ppid) scan_processes.reject { |p| p.ppid == current_ppid } end |
#leftover_sockets(current_ppid: Process.ppid) ⇒ Object
392 393 394 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 392 def leftover_sockets(current_ppid: Process.ppid) scan_sockets.reject { |s| s[:ppid] == current_ppid } end |
#own_processes(current_ppid: Process.ppid) ⇒ Object
384 385 386 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 384 def own_processes(current_ppid: Process.ppid) scan_processes.select { |p| p.ppid == current_ppid } end |
#shutdown(current_ppid: Process.ppid, caller: '') ⇒ Object
401 402 403 404 405 406 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 401 def shutdown(current_ppid: Process.ppid, caller: '') SvelteOnRails::Lib::Utils.ssr_server_log("Shutting down SSR client, ppid: #{current_ppid} (#{caller})") terminate_processes(own_processes(current_ppid: current_ppid), label: "own") ensure File.delete(ssr_client_ppid_file) if File.exist?(ssr_client_ppid_file) end |
#ssr_client_ppid_file ⇒ Object
351 352 353 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 351 def ssr_client_ppid_file Rails.root.join("tmp", "pids", 'svelte_on_rails.ppid') end |
#start_node_server_command(started_by, ppid: Process.ppid) ⇒ Object
371 372 373 374 375 376 377 378 379 380 |
# File 'lib/svelte_on_rails/ssr_client.rb', line 371 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 |