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.
340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 340 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
336 337 338 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 336 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
336 337 338 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 336 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
336 337 338 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 336 def ssr_server_bin_path @ssr_server_bin_path end |
Instance Method Details
#cleanup_leftover_processes(current_ppid: Process.ppid) ⇒ Object
397 398 399 400 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 397 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
389 390 391 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 389 def leftover_processes(current_ppid: Process.ppid) scan_processes.reject { |p| p.ppid == current_ppid } end |
#leftover_sockets(current_ppid: Process.ppid) ⇒ Object
393 394 395 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 393 def leftover_sockets(current_ppid: Process.ppid) scan_sockets.reject { |s| s[:ppid] == current_ppid } end |
#own_processes(current_ppid: Process.ppid) ⇒ Object
385 386 387 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 385 def own_processes(current_ppid: Process.ppid) scan_processes.select { |p| p.ppid == current_ppid } end |
#shutdown(current_ppid: Process.ppid) ⇒ Object
402 403 404 405 406 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 402 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
352 353 354 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 352 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
372 373 374 375 376 377 378 379 380 381 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 372 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
408 409 410 411 412 413 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 408 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 |