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
- #logfile ⇒ Object
- #own_processes(current_ppid: Process.ppid) ⇒ Object
- #secure_log(msg) ⇒ Object
- #shutdown(current_ppid: Process.ppid) ⇒ Object
- #ssr_server_ppid_file ⇒ Object
- #start_node_server_command(started_by, ppid: Process.ppid) ⇒ Object
Constructor Details
#initialize ⇒ SsrServerHelpers
Returns a new instance of SsrServerHelpers.
342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 342 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
338 339 340 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 338 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
338 339 340 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 338 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
338 339 340 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 338 def ssr_server_bin_path @ssr_server_bin_path end |
Instance Method Details
#cleanup_leftover_processes(current_ppid: Process.ppid) ⇒ Object
399 400 401 402 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 399 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
391 392 393 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 391 def leftover_processes(current_ppid: Process.ppid) scan_processes.reject { |p| p.ppid == current_ppid } end |
#leftover_sockets(current_ppid: Process.ppid) ⇒ Object
395 396 397 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 395 def leftover_sockets(current_ppid: Process.ppid) scan_sockets.reject { |s| s[:ppid] == current_ppid } end |
#logfile ⇒ Object
419 420 421 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 419 def logfile Rails.root.join("log", "svelte_ssr_server.log") end |
#own_processes(current_ppid: Process.ppid) ⇒ Object
387 388 389 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 387 def own_processes(current_ppid: Process.ppid) scan_processes.select { |p| p.ppid == current_ppid } end |
#secure_log(msg) ⇒ Object
410 411 412 413 414 415 416 417 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 410 def secure_log(msg) File.open(logfile, 'a') do |f| f.sync = true f.puts("[#{Time.now.utc.iso8601(3)} ppid:#{Process.ppid} pid:#{Process.pid}] #{msg}") end end |
#shutdown(current_ppid: Process.ppid) ⇒ Object
404 405 406 407 408 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 404 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
354 355 356 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 354 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
374 375 376 377 378 379 380 381 382 383 |
# File 'lib/svelte_on_rails/ssr_server.rb', line 374 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 |