svelte-on-rails 23.0.2 → 23.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c733c4ddc2d785a0534720152724d64f8e61a6334b4ba76c0f6f1cbac1fe7da
4
- data.tar.gz: faa9b3a2ccd3c5deef64a31f65a0e6d5d3b5d5687ce7836b9f20f7b83175decd
3
+ metadata.gz: 26d47863e0d0203a1e3eb22d690621ec1710f24b2f6e6808af0bebb159e8c658
4
+ data.tar.gz: bda202fb4a438357d2d50d74caf97cb1aa9bc8b4408b7adb758dd9b2c3e50476
5
5
  SHA512:
6
- metadata.gz: b42c8269255b5958b294501ba7d655576dad6e83d99d9e2b2e28618fa063eed83a41dfa8b91a1b3384bfa6c4a4ae3935deb2184e303b50dc2070a835b5718ce5
7
- data.tar.gz: e07230f03d3d7b430045fb76505d15c8d197a1dadf74655edac1c44592c032e3f4456b2e5adc0138ea45c99da1fc3e5bb70705e60141fc6e4f56ac22931b5863
6
+ metadata.gz: 44513e768c709b976ec016a2381a95565b6d933da6a9fe4d81fcc534e2e35ec5a4a6a76cb1fae659b0eb54531468a9e8c940cb3648f8465b120b6eca780b4a37
7
+ data.tar.gz: d4c83202c7c4137c715fa54cd1ca6f80a7be1be2bc71291a6a6e15b66fd47e36d642752a94e98e26d1b2ce49eb6a890822c8f01bb2568488dbe631bb502eb8fa
@@ -35,6 +35,10 @@ require 'generators/showcase_generator'
35
35
  require 'digest/xxhash'
36
36
  require 'benchmark'
37
37
 
38
+ # for rake tasks
39
+
40
+ require 'svelte_on_rails/cache'
41
+
38
42
  module SvelteOnRails
39
43
  class << self
40
44
  def configuration
@@ -0,0 +1,56 @@
1
+ module SvelteOnRails
2
+ module Cache
3
+ module_function
4
+
5
+ def redis_entries(silent: false)
6
+ conf = SvelteOnRails::Configuration.instance
7
+ redis = conf.redis_instance
8
+ namespace = conf.redis_namespace
9
+
10
+ unless redis
11
+ warn "svelte_on_rails:show_cache — no redis_instance configured, nothing to show."
12
+ return []
13
+ end
14
+
15
+ pattern = "#{namespace}*"
16
+
17
+ puts "Scanning Redis for keys matching «#{pattern}» ..." unless silent
18
+
19
+ entries = [] # [{ key:, bytes:, ttl:, type: }]
20
+ cursor = "0"
21
+
22
+ loop do
23
+ cursor, keys = redis.scan(cursor, match: pattern)
24
+
25
+ if keys.any?
26
+ # Pipeline MEMORY USAGE / TTL / TYPE for the whole batch.
27
+ results = redis.pipelined do |p|
28
+ keys.each do |k|
29
+ p.call(["MEMORY", "USAGE", k])
30
+ p.ttl(k)
31
+ p.type(k)
32
+ end
33
+ end
34
+
35
+ keys.each_with_index do |k, i|
36
+ bytes = results[i * 3]
37
+ ttl = results[i * 3 + 1]
38
+ type = results[i * 3 + 2]
39
+ entries << { key: k, bytes: bytes.to_i, ttl: ttl.to_i, type: type }
40
+ end
41
+ end
42
+
43
+ break if cursor == "0"
44
+ rescue => e
45
+ warn "svelte_on_rails:show_cache — error during scan: #{e.class}: #{e.message}"
46
+ break
47
+ end
48
+
49
+ if entries.empty?
50
+ puts "No keys found under «#{pattern}»."
51
+ return []
52
+ end
53
+ entries
54
+ end
55
+ end
56
+ end
@@ -314,8 +314,8 @@ module SvelteOnRails
314
314
 
315
315
  # npm package version
316
316
 
317
- if Gem::Version.new(version) < Gem::Version.new('15.0.0')
318
- raise "[Svelte-on-Rails] NPM-Package @csedl/svelte-on-rails: At least version 15.0.0 is required, but found: «#{sor}»"
317
+ if Gem::Version.new(version) < Gem::Version.new('15.2.0')
318
+ raise "[Svelte-on-Rails] NPM-Package @csedl/svelte-on-rails: At least version 15.2.0 is required, but found: «#{sor}»"
319
319
  end
320
320
 
321
321
  # check version
@@ -23,7 +23,7 @@ module SvelteOnRails
23
23
 
24
24
  @initialized_by = caller
25
25
 
26
- if ssr_startup_leader?
26
+ if startup_leader?
27
27
  File.open(SvelteOnRails::Lib::Utils.ssr_server_logfile, 'w') do |f|
28
28
  f.sync = true
29
29
  f.puts("[#{Time.now.utc.iso8601(3)} ppid:#{Process.ppid} pid:#{Process.pid}] >>> Logfile deleted on initializing SsrClient, called by #{caller} <<<")
@@ -45,11 +45,11 @@ module SvelteOnRails
45
45
 
46
46
  File.delete(restart_marker_file) if File.exist?(restart_marker_file)
47
47
 
48
- SvelteOnRails::SsrClientControlChannel.install_control_listener if ssr_startup_leader?
48
+ SvelteOnRails::SsrClientControlChannel.install_control_listener if startup_leader?
49
49
 
50
50
  if @ssr_server
51
51
 
52
- start_node_server! if ssr_startup_leader?
52
+ start_node_server! if startup_leader?
53
53
 
54
54
  at_exit do
55
55
  shutdown(caller: 'at_exit')
@@ -319,35 +319,34 @@ module SvelteOnRails
319
319
 
320
320
  private
321
321
 
322
- def ssr_startup_leader?
323
- return @ssr_startup_leader unless @ssr_startup_leader.nil?
322
+ def startup_leader?
323
+ return @startup_leader unless @startup_leader.nil?
324
324
 
325
325
  FileUtils.mkdir_p(File.dirname(flock_file))
326
326
 
327
- @ssr_startup_flock_file = File.open(flock_file, File::RDWR | File::CREAT, 0o644)
327
+ flock = File.open(flock_file, File::RDWR | File::CREAT, 0o644)
328
328
 
329
- if @ssr_startup_flock_file.flock(File::LOCK_EX | File::LOCK_NB)
329
+ if flock.flock(File::LOCK_EX | File::LOCK_NB)
330
330
  SvelteOnRails::Lib::Utils.ssr_server_log(
331
- "SSR startup leader elected: pid=#{Process.pid}, ppid=#{Process.ppid}",
331
+ "Startup leader process elected: pid=#{Process.pid}, ppid=#{Process.ppid}",
332
332
  ssr_logfile_only: true
333
333
  )
334
- @ssr_startup_leader = true
334
+ @startup_leader = true
335
335
  else
336
- @ssr_startup_flock_file.close
337
- @ssr_startup_flock_file = nil
336
+ flock.close
338
337
 
339
338
  SvelteOnRails::Lib::Utils.ssr_server_log(
340
- "SSR startup leader already exists; skipping Node startup in pid=#{Process.pid}, ppid=#{Process.ppid}",
339
+ "Startup leader already exists; skipping Node startup in pid=#{Process.pid}, ppid=#{Process.ppid}",
341
340
  ssr_logfile_only: true
342
341
  )
343
- @ssr_startup_leader = false
342
+ @startup_leader = false
344
343
  end
345
344
 
346
- @ssr_startup_leader
345
+ @startup_leader
347
346
  end
348
347
 
349
348
  def flock_file
350
- Rails.root.join('tmp', 'sockets', "svelte-ssr-#{Process.ppid}.flock")
349
+ Rails.root.join('tmp', 'sockets', "sor-startup-leader-#{Process.ppid}.flock")
351
350
  end
352
351
 
353
352
  def cleanup_flock_file_later
@@ -52,7 +52,7 @@ namespace :svelte_on_rails do
52
52
  desc "Show all svelte-on-rails Redis keys with their memory footprint (scoped to redis_namespace). Env: LIMIT=n, SORT=size|key, PATTERN=extra-glob"
53
53
  task show: :environment do
54
54
 
55
- _entries = entries
55
+ _entries = SvelteOnRails::Cache.redis_entries
56
56
 
57
57
  _entries.sort_by! { |e| -e[:bytes] }
58
58
 
@@ -104,58 +104,6 @@ namespace :svelte_on_rails do
104
104
  end
105
105
 
106
106
  end
107
-
108
-
109
- def entries
110
- conf = SvelteOnRails::Configuration.instance
111
- redis = conf.redis_instance
112
- namespace = conf.redis_namespace
113
-
114
- unless redis
115
- warn "svelte_on_rails:show_cache — no redis_instance configured, nothing to show."
116
- return []
117
- end
118
-
119
- pattern = "#{namespace}*"
120
-
121
- puts "Scanning Redis for keys matching «#{pattern}» ..."
122
-
123
- entries = [] # [{ key:, bytes:, ttl:, type: }]
124
- cursor = "0"
125
-
126
- loop do
127
- cursor, keys = redis.scan(cursor, match: pattern)
128
-
129
- if keys.any?
130
- # Pipeline MEMORY USAGE / TTL / TYPE for the whole batch.
131
- results = redis.pipelined do |p|
132
- keys.each do |k|
133
- p.call(["MEMORY", "USAGE", k])
134
- p.ttl(k)
135
- p.type(k)
136
- end
137
- end
138
-
139
- keys.each_with_index do |k, i|
140
- bytes = results[i * 3]
141
- ttl = results[i * 3 + 1]
142
- type = results[i * 3 + 2]
143
- entries << { key: k, bytes: bytes.to_i, ttl: ttl.to_i, type: type }
144
- end
145
- end
146
-
147
- break if cursor == "0"
148
- rescue => e
149
- warn "svelte_on_rails:show_cache — error during scan: #{e.class}: #{e.message}"
150
- break
151
- end
152
-
153
- if entries.empty?
154
- puts "No keys found under «#{pattern}»."
155
- return []
156
- end
157
- entries
158
- end
159
107
  end
160
108
  end
161
109
 
@@ -13,6 +13,8 @@ namespace :svelte_on_rails do
13
13
  configs = SvelteOnRails::Configuration.instance
14
14
  socket_path = client_status[:socket_path]
15
15
 
16
+ puts client_status.to_s
17
+
16
18
  puts
17
19
  puts '=' * @line_width
18
20
  puts
@@ -50,6 +52,38 @@ namespace :svelte_on_rails do
50
52
  puts
51
53
  end
52
54
 
55
+ # MEMORY USAGE
56
+
57
+ puts '=' * @line_width
58
+ puts
59
+ puts 'MEMORY USAGE:'
60
+ puts
61
+ if !curl_installed
62
+ puts ' ERROR: curl is not installed on this machine, unable to check memory usage for node server.'
63
+ else
64
+ curl_cmd2 = "curl --unix-socket #{socket_path} http://localhost/health"
65
+ stdout, stderr, status = Open3.capture3(curl_cmd2)
66
+ pids = JSON.parse(stdout)['pids']
67
+
68
+ if pids.empty?
69
+ puts ' Node workers memory: no node worker PIDs found'
70
+ else
71
+ ps_cmd = "ps -o rss= -p #{pids.join(',')}"
72
+ ps_stdout, ps_stderr, ps_status = Open3.capture3(ps_cmd)
73
+ total_kb = ps_stdout.each_line.sum { |line| line.to_i }
74
+
75
+ puts " #{human_bytes(total_kb*1024)} for #{pids.size} node #{'worker'.pluralize(pids.size)}"
76
+
77
+ redis_entries = SvelteOnRails::Cache.redis_entries(silent: true)
78
+ total_bytes = redis_entries.sum { |e| e[:bytes] }
79
+ puts " #{human_bytes(total_bytes)} for #{redis_entries.size} Redis #{'key'.pluralize(redis_entries.size)}"
80
+ end
81
+ end
82
+ puts
83
+
84
+
85
+ # ADDITIONAL INFO
86
+
53
87
  puts '=' * @line_width
54
88
  puts
55
89
  puts 'ADDITIONAL INFO:'
@@ -25,6 +25,9 @@ function getSvelteEntries(): string[] {
25
25
  const entries = getSvelteEntries()
26
26
 
27
27
  export default defineConfig({
28
+
29
+ publicDir: false,
30
+
28
31
  plugins: [
29
32
  svelte({
30
33
  compilerOptions: {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 23.0.2
4
+ version: 23.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
@@ -75,6 +75,7 @@ files:
75
75
  - lib/svelte-on-rails.rb
76
76
  - lib/svelte_on_rails/action_cable.rb
77
77
  - lib/svelte_on_rails/active_record_extensions.rb
78
+ - lib/svelte_on_rails/cache.rb
78
79
  - lib/svelte_on_rails/configuration.rb
79
80
  - lib/svelte_on_rails/installer/gem_utils.rb
80
81
  - lib/svelte_on_rails/installer/haml.rb