bidi2pdf 0.1.16 → 0.1.18

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -2
  3. data/README.md +145 -0
  4. data/docker/Dockerfile +7 -0
  5. data/docker/Dockerfile.chromedriver +7 -0
  6. data/docker/Dockerfile.slim +7 -0
  7. data/lib/bidi2pdf/bidi/buffered_web_socket_client.rb +9 -0
  8. data/lib/bidi2pdf/bidi/commands/browsing_context_get_tree.rb +16 -0
  9. data/lib/bidi2pdf/bidi/commands/cdp_send_command.rb +25 -0
  10. data/lib/bidi2pdf/bidi/commands.rb +2 -0
  11. data/lib/bidi2pdf/bidi/session.rb +57 -24
  12. data/lib/bidi2pdf/chrome_sweeper/inspector.rb +117 -0
  13. data/lib/bidi2pdf/chrome_sweeper/settings.rb +79 -0
  14. data/lib/bidi2pdf/chrome_sweeper.rb +398 -0
  15. data/lib/bidi2pdf/chromedriver_api.rb +72 -0
  16. data/lib/bidi2pdf/cli/session_commands.rb +82 -0
  17. data/lib/bidi2pdf/cli.rb +43 -0
  18. data/lib/bidi2pdf/dsl.rb +2 -1
  19. data/lib/bidi2pdf/launcher.rb +2 -1
  20. data/lib/bidi2pdf/session_registry/heartbeat.rb +83 -0
  21. data/lib/bidi2pdf/session_registry.rb +152 -0
  22. data/lib/bidi2pdf/session_sweeper.rb +66 -0
  23. data/lib/bidi2pdf/session_warmer.rb +112 -1
  24. data/lib/bidi2pdf/version.rb +1 -1
  25. data/lib/bidi2pdf.rb +4 -0
  26. data/sig/bidi2pdf/bidi/buffered_web_socket_client.rbs +7 -0
  27. data/sig/bidi2pdf/bidi/commands/browsing_context_get_tree.rbs +12 -0
  28. data/sig/bidi2pdf/bidi/commands/cdp_send_command.rbs +23 -0
  29. data/sig/bidi2pdf/bidi/session.rbs +25 -3
  30. data/sig/bidi2pdf/chrome_sweeper/inspector.rbs +61 -0
  31. data/sig/bidi2pdf/chrome_sweeper/settings.rbs +34 -0
  32. data/sig/bidi2pdf/chrome_sweeper.rbs +220 -0
  33. data/sig/bidi2pdf/chromedriver_api.rbs +44 -0
  34. data/sig/bidi2pdf/cli/session_commands.rbs +35 -0
  35. data/sig/bidi2pdf/cli.rbs +6 -0
  36. data/sig/bidi2pdf/session_registry/heartbeat.rbs +47 -0
  37. data/sig/bidi2pdf/session_registry.rbs +75 -0
  38. data/sig/bidi2pdf/session_sweeper.rbs +37 -0
  39. data/sig/bidi2pdf/session_warmer.rbs +66 -0
  40. data/sig/bidi2pdf/version.rbs +1 -1
  41. metadata +29 -3
@@ -42,6 +42,12 @@ module Bidi2pdf
42
42
 
43
43
  @reaper_wakeup: untyped
44
44
 
45
+ @own_sessions: untyped
46
+
47
+ @registry: untyped
48
+
49
+ @sweeper: untyped
50
+
45
51
  @reaper: untyped
46
52
 
47
53
  # Configuration for the session warmer.
@@ -58,6 +64,12 @@ module Bidi2pdf
58
64
 
59
65
  @max_idle_age: untyped
60
66
 
67
+ @orphan_age: untyped
68
+
69
+ @registry_dir: untyped
70
+
71
+ @sweeper: untyped
72
+
61
73
  # @return [Integer] Number of Chrome slots to keep pre-warmed.
62
74
  attr_accessor size: untyped
63
75
 
@@ -84,10 +96,32 @@ module Bidi2pdf
84
96
  # 1.25x this value even when no render ever comes. +nil+ disables the limit.
85
97
  attr_accessor max_idle_age: untyped
86
98
 
99
+ # @return [Numeric, Symbol, nil] Seconds after which a session recorded by any warmer on the
100
+ # same remote chromedriver counts as left behind - its process died without closing it - and
101
+ # is closed when a warmer starts (SessionSweeper). +:auto+ (the default) is twice
102
+ # max_idle_age: a live warmer recycles its own spares within ~1.25x of that, so no live
103
+ # process's slot is ever taken. +nil+ disables the sweep. Remote mode only.
104
+ attr_accessor orphan_age: untyped
105
+
106
+ # @return [String, nil] Directory for the session registry file (SessionRegistry); +nil+ means
107
+ # Dir.tmpdir. Every process that should clean up after the others must share it.
108
+ attr_accessor registry_dir: untyped
109
+
110
+ # @return [Hash, nil] Options for a ChromeSweeper on the remote chromedriver (+scope+,
111
+ # +orphan_age+, +min_age+, +unresponsive_checks+, +max_sessions+, +pids_limit+, +interval+,
112
+ # ...), or +nil+ (default) for none. This warmer's own sessions are never touched by it; with
113
+ # an +interval+ it sweeps in the background, and a session that fails to start triggers one
114
+ # sweep and one retry. Remote mode only.
115
+ attr_accessor sweeper: untyped
116
+
87
117
  DEFAULT_MAX_IDLE_AGE: 300
88
118
 
89
119
  def initialize: () -> void
90
120
 
121
+ # The orphan age in seconds, or nil when the sweep is off (also when +:auto+ has no
122
+ # max_idle_age to derive it from).
123
+ def effective_orphan_age: () -> untyped
124
+
91
125
  # @raise [ArgumentError] if a setting can't be honored - checked once, at construction.
92
126
  def validate!: () -> untyped
93
127
 
@@ -96,6 +130,10 @@ module Bidi2pdf
96
130
  def validate_size!: () -> (nil | untyped)
97
131
 
98
132
  def validate_max_idle_age!: () -> (nil | untyped)
133
+
134
+ def validate_orphan_age!: () -> (nil | untyped)
135
+
136
+ def validate_sweeper!: () -> (nil | untyped)
99
137
  end
100
138
 
101
139
  # Configures the warmer and eagerly (re)creates the singleton, warming config.size slots right
@@ -126,6 +164,10 @@ module Bidi2pdf
126
164
  # Checks out a slot, yields a fresh tab for one render, then retires the slot.
127
165
  def self.with_tab: () { (?) -> untyped } -> untyped
128
166
 
167
+ # Sweeps the remote chromedriver with the configured sweeper; nil when there is none (or no
168
+ # warmer yet - this never creates one).
169
+ def self.sweep!: (?reason: ::Symbol) -> untyped
170
+
129
171
  # Retires every currently-warm spare and resets the singleton.
130
172
  def self.shutdown: () -> untyped
131
173
 
@@ -143,6 +185,11 @@ module Bidi2pdf
143
185
 
144
186
  def initialize: (untyped config, ?slot_factory: untyped?) -> void
145
187
 
188
+ # Sweeps the remote chromedriver now - for an application that suspects leaked sessions.
189
+ #
190
+ # @return [ChromeSweeper::Result, nil] nil when no sweeper is configured.
191
+ def sweep!: (?reason: ::Symbol) -> untyped
192
+
146
193
  # Checks out a slot, creates an isolated UserContext/Window/Tab for one render, yields the tab,
147
194
  # then unconditionally closes those resources and retires the underlying slot.
148
195
  def with_tab: () { (untyped) -> untyped } -> untyped
@@ -161,6 +208,23 @@ module Bidi2pdf
161
208
 
162
209
  def create_slot: () -> untyped
163
210
 
211
+ # A chromedriver out of room for another Chrome refuses the session; with a sweeper, close
212
+ # everything nobody holds (a pressure sweep) and try once more.
213
+ def new_slot: () -> untyped
214
+
215
+ def start_background_work: () -> untyped
216
+
217
+ def build_sweeper: () -> (nil | untyped)
218
+
219
+ # Remote mode with an orphan age or a sweeper: sessions are recorded, so a later start (or the
220
+ # sweeper, whose default scope is :recorded) can close the ones this process leaves behind if it
221
+ # dies uncleanly. The start-up sweep itself needs the orphan age - see #sweep_leftovers.
222
+ def build_registry: () -> (nil | untyped)
223
+
224
+ def sweep_leftovers: () -> (nil | untyped)
225
+
226
+ def session_id_of: (untyped slot) -> untyped
227
+
164
228
  # Session#started? is just an internal flag set once at startup - it never flips back if Chrome,
165
229
  # ChromeDriver, or the WebSocket dies externally while a slot sits idle in the cache. The
166
230
  # client's own #open? is kept live by the reader thread noticing a real socket error, so
@@ -214,6 +278,8 @@ module Bidi2pdf
214
278
  # reservation is released here, in the same critical section as the stash.
215
279
  def stash_or_retire: (untyped slot) -> untyped
216
280
 
281
+ # Forgotten only after closing: a process that dies in between leaves a record whose session is
282
+ # already gone - the next sweep just drops it - never an open session nobody knows about.
217
283
  def retire: (untyped slot) -> untyped
218
284
 
219
285
  def safe_close: (untyped label) { (?) -> untyped } -> untyped
@@ -1,3 +1,3 @@
1
1
  module Bidi2pdf
2
- VERSION: "0.1.16"
2
+ VERSION: "0.1.18"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bidi2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter S.
@@ -87,16 +87,22 @@ dependencies:
87
87
  name: rubyzip
88
88
  requirement: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - "~>"
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '2.4'
93
+ - - "<"
94
+ - !ruby/object:Gem::Version
95
+ version: '4.0'
93
96
  type: :runtime
94
97
  prerelease: false
95
98
  version_requirements: !ruby/object:Gem::Requirement
96
99
  requirements:
97
- - - "~>"
100
+ - - ">="
98
101
  - !ruby/object:Gem::Version
99
102
  version: '2.4'
103
+ - - "<"
104
+ - !ruby/object:Gem::Version
105
+ version: '4.0'
100
106
  - !ruby/object:Gem::Dependency
101
107
  name: sys-proctable
102
108
  requirement: !ruby/object:Gem::Requirement
@@ -423,11 +429,13 @@ files:
423
429
  - lib/bidi2pdf/bidi/commands/browser_create_user_context.rb
424
430
  - lib/bidi2pdf/bidi/commands/browser_remove_user_context.rb
425
431
  - lib/bidi2pdf/bidi/commands/browsing_context_close.rb
432
+ - lib/bidi2pdf/bidi/commands/browsing_context_get_tree.rb
426
433
  - lib/bidi2pdf/bidi/commands/browsing_context_navigate.rb
427
434
  - lib/bidi2pdf/bidi/commands/browsing_context_print.rb
428
435
  - lib/bidi2pdf/bidi/commands/cancel_auth.rb
429
436
  - lib/bidi2pdf/bidi/commands/capture_screenshot.rb
430
437
  - lib/bidi2pdf/bidi/commands/cdp_get_session.rb
438
+ - lib/bidi2pdf/bidi/commands/cdp_send_command.rb
431
439
  - lib/bidi2pdf/bidi/commands/create_tab.rb
432
440
  - lib/bidi2pdf/bidi/commands/create_window.rb
433
441
  - lib/bidi2pdf/bidi/commands/get_user_contexts.rb
@@ -457,9 +465,14 @@ files:
457
465
  - lib/bidi2pdf/bidi/session.rb
458
466
  - lib/bidi2pdf/bidi/user_context.rb
459
467
  - lib/bidi2pdf/bidi/web_socket_dispatcher.rb
468
+ - lib/bidi2pdf/chrome_sweeper.rb
469
+ - lib/bidi2pdf/chrome_sweeper/inspector.rb
470
+ - lib/bidi2pdf/chrome_sweeper/settings.rb
471
+ - lib/bidi2pdf/chromedriver_api.rb
460
472
  - lib/bidi2pdf/chromedriver_manager.rb
461
473
  - lib/bidi2pdf/cli.rb
462
474
  - lib/bidi2pdf/cli/json_output.rb
475
+ - lib/bidi2pdf/cli/session_commands.rb
463
476
  - lib/bidi2pdf/diagnose.rb
464
477
  - lib/bidi2pdf/dsl.rb
465
478
  - lib/bidi2pdf/error_codes.rb
@@ -481,7 +494,10 @@ files:
481
494
  - lib/bidi2pdf/result.rb
482
495
  - lib/bidi2pdf/result_collector.rb
483
496
  - lib/bidi2pdf/schema.rb
497
+ - lib/bidi2pdf/session_registry.rb
498
+ - lib/bidi2pdf/session_registry/heartbeat.rb
484
499
  - lib/bidi2pdf/session_runner.rb
500
+ - lib/bidi2pdf/session_sweeper.rb
485
501
  - lib/bidi2pdf/session_warmer.rb
486
502
  - lib/bidi2pdf/test_helpers.rb
487
503
  - lib/bidi2pdf/test_helpers/configuration.rb
@@ -521,11 +537,13 @@ files:
521
537
  - sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs
522
538
  - sig/bidi2pdf/bidi/commands/browser_remove_user_context.rbs
523
539
  - sig/bidi2pdf/bidi/commands/browsing_context_close.rbs
540
+ - sig/bidi2pdf/bidi/commands/browsing_context_get_tree.rbs
524
541
  - sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs
525
542
  - sig/bidi2pdf/bidi/commands/browsing_context_print.rbs
526
543
  - sig/bidi2pdf/bidi/commands/cancel_auth.rbs
527
544
  - sig/bidi2pdf/bidi/commands/capture_screenshot.rbs
528
545
  - sig/bidi2pdf/bidi/commands/cdp_get_session.rbs
546
+ - sig/bidi2pdf/bidi/commands/cdp_send_command.rbs
529
547
  - sig/bidi2pdf/bidi/commands/create_tab.rbs
530
548
  - sig/bidi2pdf/bidi/commands/create_window.rbs
531
549
  - sig/bidi2pdf/bidi/commands/get_user_contexts.rbs
@@ -555,9 +573,14 @@ files:
555
573
  - sig/bidi2pdf/bidi/session.rbs
556
574
  - sig/bidi2pdf/bidi/user_context.rbs
557
575
  - sig/bidi2pdf/bidi/web_socket_dispatcher.rbs
576
+ - sig/bidi2pdf/chrome_sweeper.rbs
577
+ - sig/bidi2pdf/chrome_sweeper/inspector.rbs
578
+ - sig/bidi2pdf/chrome_sweeper/settings.rbs
579
+ - sig/bidi2pdf/chromedriver_api.rbs
558
580
  - sig/bidi2pdf/chromedriver_manager.rbs
559
581
  - sig/bidi2pdf/cli.rbs
560
582
  - sig/bidi2pdf/cli/json_output.rbs
583
+ - sig/bidi2pdf/cli/session_commands.rbs
561
584
  - sig/bidi2pdf/diagnose.rbs
562
585
  - sig/bidi2pdf/dsl.rbs
563
586
  - sig/bidi2pdf/error_codes.rbs
@@ -579,7 +602,10 @@ files:
579
602
  - sig/bidi2pdf/result.rbs
580
603
  - sig/bidi2pdf/result_collector.rbs
581
604
  - sig/bidi2pdf/schema.rbs
605
+ - sig/bidi2pdf/session_registry.rbs
606
+ - sig/bidi2pdf/session_registry/heartbeat.rbs
582
607
  - sig/bidi2pdf/session_runner.rbs
608
+ - sig/bidi2pdf/session_sweeper.rbs
583
609
  - sig/bidi2pdf/session_warmer.rbs
584
610
  - sig/bidi2pdf/test_helpers.rbs
585
611
  - sig/bidi2pdf/test_helpers/configuration.rbs