Class: SvelteOnRails::SsrServerHelpers

Inherits:
Object
  • Object
show all
Defined in:
lib/svelte_on_rails/ssr_server.rb

Defined Under Namespace

Classes: SsrProcess

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSsrServerHelpers

Returns a new instance of SsrServerHelpers.



334
335
336
337
338
339
340
341
342
343
344
# File 'lib/svelte_on_rails/ssr_server.rb', line 334

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_namespaceObject (readonly)

theese helpers are used from the :check rake task For that reason they are within a separate class



330
331
332
# File 'lib/svelte_on_rails/ssr_server.rb', line 330

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



330
331
332
# File 'lib/svelte_on_rails/ssr_server.rb', line 330

def socket_path
  @socket_path
end

#ssr_server_bin_pathObject (readonly)

theese helpers are used from the :check rake task For that reason they are within a separate class



330
331
332
# File 'lib/svelte_on_rails/ssr_server.rb', line 330

def ssr_server_bin_path
  @ssr_server_bin_path
end

Instance Method Details

#cleanup_leftover_processes(current_ppid: Process.ppid) ⇒ Object



391
392
393
394
# File 'lib/svelte_on_rails/ssr_server.rb', line 391

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



383
384
385
# File 'lib/svelte_on_rails/ssr_server.rb', line 383

def leftover_processes(current_ppid: Process.ppid)
  scan_processes.reject { |p| p.ppid == current_ppid }
end

#leftover_sockets(current_ppid: Process.ppid) ⇒ Object



387
388
389
# File 'lib/svelte_on_rails/ssr_server.rb', line 387

def leftover_sockets(current_ppid: Process.ppid)
  scan_sockets.reject { |s| s[:ppid] == current_ppid }
end

#own_processes(current_ppid: Process.ppid) ⇒ Object



379
380
381
# File 'lib/svelte_on_rails/ssr_server.rb', line 379

def own_processes(current_ppid: Process.ppid)
  scan_processes.select { |p| p.ppid == current_ppid }
end

#shutdown(current_ppid: Process.ppid) ⇒ Object



396
397
398
399
400
# File 'lib/svelte_on_rails/ssr_server.rb', line 396

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_fileObject



346
347
348
# File 'lib/svelte_on_rails/ssr_server.rb', line 346

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



366
367
368
369
370
371
372
373
374
375
# File 'lib/svelte_on_rails/ssr_server.rb', line 366

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