bluepill 0.2.9 → 0.3.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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -2
  3. data/README.md +12 -7
  4. data/bin/bluepill +8 -2
  5. data/bluepill.gemspec +1 -1
  6. data/lib/bluepill/application/lifecycle.rb +44 -34
  7. data/lib/bluepill/application/listener.rb +1 -1
  8. data/lib/bluepill/application/previous_daemon.rb +12 -14
  9. data/lib/bluepill/application.rb +33 -29
  10. data/lib/bluepill/base_directory.rb +18 -20
  11. data/lib/bluepill/check_registry.rb +104 -0
  12. data/lib/bluepill/clock.rb +1 -3
  13. data/lib/bluepill/condition_watch.rb +45 -54
  14. data/lib/bluepill/controller/directory.rb +1 -3
  15. data/lib/bluepill/controller.rb +32 -37
  16. data/lib/bluepill/dsl/app_proxy.rb +68 -64
  17. data/lib/bluepill/dsl/attributes.rb +135 -0
  18. data/lib/bluepill/dsl/process_factory/child_factory.rb +80 -0
  19. data/lib/bluepill/dsl/process_factory/registry.rb +6 -26
  20. data/lib/bluepill/dsl/process_factory.rb +83 -84
  21. data/lib/bluepill/dsl/process_proxy.rb +61 -168
  22. data/lib/bluepill/dsl.rb +16 -15
  23. data/lib/bluepill/errors.rb +190 -0
  24. data/lib/bluepill/group.rb +14 -37
  25. data/lib/bluepill/logger.rb +55 -97
  26. data/lib/bluepill/process/attributes.rb +66 -32
  27. data/lib/bluepill/process/children.rb +4 -6
  28. data/lib/bluepill/process/pid.rb +41 -35
  29. data/lib/bluepill/process/state_machine.rb +15 -59
  30. data/lib/bluepill/process/stop_signals.rb +120 -0
  31. data/lib/bluepill/process/transition.rb +1 -3
  32. data/lib/bluepill/process/transition_callbacks.rb +2 -16
  33. data/lib/bluepill/process/triggers.rb +90 -0
  34. data/lib/bluepill/process/user_commands.rb +1 -1
  35. data/lib/bluepill/process/watches.rb +9 -23
  36. data/lib/bluepill/process.rb +55 -52
  37. data/lib/bluepill/process_commands/execution.rb +14 -22
  38. data/lib/bluepill/process_commands/hooks.rb +1 -31
  39. data/lib/bluepill/process_commands/stop_signals.rb +12 -17
  40. data/lib/bluepill/process_commands.rb +10 -8
  41. data/lib/bluepill/process_conditions/always_true.rb +2 -6
  42. data/lib/bluepill/process_conditions/below_threshold.rb +6 -8
  43. data/lib/bluepill/process_conditions/cpu_usage.rb +1 -4
  44. data/lib/bluepill/process_conditions/file_time.rb +8 -9
  45. data/lib/bluepill/process_conditions/http.rb +28 -67
  46. data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
  47. data/lib/bluepill/process_conditions/process_condition.rb +29 -47
  48. data/lib/bluepill/process_conditions/zombie_process.rb +2 -6
  49. data/lib/bluepill/process_conditions.rb +5 -14
  50. data/lib/bluepill/process_journal/cleanup.rb +5 -53
  51. data/lib/bluepill/process_journal/config.rb +73 -0
  52. data/lib/bluepill/process_journal/entries.rb +128 -0
  53. data/lib/bluepill/process_journal/journal.rb +69 -0
  54. data/lib/bluepill/process_journal/kind.rb +60 -0
  55. data/lib/bluepill/process_journal/lock.rb +9 -4
  56. data/lib/bluepill/process_journal.rb +13 -324
  57. data/lib/bluepill/process_statistics.rb +3 -7
  58. data/lib/bluepill/socket.rb +19 -17
  59. data/lib/bluepill/system/command_options.rb +135 -0
  60. data/lib/bluepill/system/command_result.rb +73 -0
  61. data/lib/bluepill/system/command_setup.rb +3 -4
  62. data/lib/bluepill/system/commands.rb +21 -18
  63. data/lib/bluepill/system/daemon.rb +19 -14
  64. data/lib/bluepill/system/files.rb +35 -0
  65. data/lib/bluepill/system/ps.rb +20 -17
  66. data/lib/bluepill/system/ps_table.rb +7 -9
  67. data/lib/bluepill/system/usage.rb +155 -0
  68. data/lib/bluepill/system.rb +7 -192
  69. data/lib/bluepill/trigger.rb +18 -69
  70. data/lib/bluepill/triggers/flapping.rb +12 -8
  71. data/lib/bluepill/units.rb +7 -21
  72. data/lib/bluepill/version.rb +12 -22
  73. data/lib/bluepill.rb +1 -1
  74. data/sig/bluepill/application.rbs +11 -12
  75. data/sig/bluepill/attributes.rbs +48 -0
  76. data/sig/bluepill/checks.rbs +40 -40
  77. data/sig/bluepill/dsl.rbs +97 -60
  78. data/sig/bluepill/errors.rbs +48 -0
  79. data/sig/bluepill/logger.rbs +15 -31
  80. data/sig/bluepill/process.rbs +39 -305
  81. data/sig/bluepill/process_commands.rbs +235 -0
  82. data/sig/bluepill/stop_signals.rbs +21 -0
  83. data/sig/bluepill/system.rbs +154 -99
  84. data/sig/bluepill/version.rbs +17 -0
  85. data/sig/bluepill.rbs +1 -17
  86. data/sig/manifest.yaml +1 -0
  87. metadata +21 -8
  88. data/lib/bluepill/deprecation/custom_checks.rb +0 -193
  89. data/lib/bluepill/deprecation/dsl.rb +0 -141
  90. data/lib/bluepill/deprecation/options.rb +0 -140
  91. data/lib/bluepill/deprecation.rb +0 -92
  92. data/lib/bluepill/dsl/process_factory/children.rb +0 -99
  93. data/sig/bluepill/deprecation.rbs +0 -87
@@ -0,0 +1,48 @@
1
+ module Bluepill
2
+ # An error that stops the bluepill command, with the status it exits with
3
+ class Error < StandardError
4
+ def exit_status: () -> Integer
5
+ end
6
+
7
+ # A mistake in a pill file
8
+ class ConfigError < Error
9
+ LIBRARY_DIR: String
10
+
11
+ def location: () -> String?
12
+
13
+ private
14
+
15
+ def outside_library?: (Thread::Backtrace::Location frame) -> bool
16
+ end
17
+
18
+ # The daemon couldn't start
19
+ class StartupError < Error
20
+ end
21
+
22
+ # A previous daemon for the application couldn't be stopped
23
+ class PreviousDaemonError < Error
24
+ end
25
+
26
+ # A daemon for the application is already running
27
+ class AlreadyRunningError < Error
28
+ end
29
+
30
+ # The CLI couldn't reach the daemon
31
+ class ConnectionError < Error
32
+ end
33
+
34
+ # The daemon runs another version of bluepill
35
+ class VersionMismatchError < Error
36
+ end
37
+
38
+ # The CLI was given a command it doesn't know
39
+ class UnknownCommandError < Error
40
+ end
41
+
42
+ # The daemon answered a command with an error
43
+ class DaemonError < Error
44
+ attr_reader daemon_error: Exception
45
+
46
+ def initialize: (Exception daemon_error) -> void
47
+ end
48
+ end
@@ -21,15 +21,6 @@ module Bluepill
21
21
  def debug: (String message) -> void
22
22
  end
23
23
 
24
- type options = {
25
- ?logger: Logger,
26
- ?prefix: String?,
27
- ?stdout: bool,
28
- ?log_file: String?,
29
- ?identity: String,
30
- ?log_level: (Symbol | String)?
31
- }
32
-
33
24
  LOG_METHODS: Array[Symbol]
34
25
 
35
26
  # A ::Logger that also answers to the syslog method names
@@ -49,50 +40,43 @@ module Bluepill
49
40
  alias notice info
50
41
  end
51
42
 
52
- @options: options
53
- @logger: Logger | (Object & _Backend)
54
- @prefix: String?
55
- @stdout: bool?
43
+ @log_file: String?
44
+ @identity: String
56
45
  @level: Integer
46
+ @stdout: bool
57
47
  @names: Array[String?]
58
48
  @label: String?
49
+ # A one-element box that every logger made from the same one shares
59
50
  @sink: Array[Object & _Backend]
60
51
  @prefixes: Hash[String?, Logger]
61
52
 
62
- def initialize: (?options options) -> void
53
+ def initialize: (?logger: (Object & _Backend)?, ?stdout: bool, ?log_file: String?, ?identity: String, ?log_level: Symbol | String) -> void
63
54
 
64
- def emerg: (_ToS msg, ?Array[String?]? prefix) -> void
55
+ def emerg: (_ToS msg) -> void
65
56
 
66
- def alert: (_ToS msg, ?Array[String?]? prefix) -> void
57
+ def alert: (_ToS msg) -> void
67
58
 
68
- def crit: (_ToS msg, ?Array[String?]? prefix) -> void
59
+ def crit: (_ToS msg) -> void
69
60
 
70
- def err: (_ToS msg, ?Array[String?]? prefix) -> void
61
+ def err: (_ToS msg) -> void
71
62
 
72
- def warning: (_ToS msg, ?Array[String?]? prefix) -> void
63
+ def warning: (_ToS msg) -> void
73
64
 
74
- def notice: (_ToS msg, ?Array[String?]? prefix) -> void
65
+ def notice: (_ToS msg) -> void
75
66
 
76
- def info: (_ToS msg, ?Array[String?]? prefix) -> void
67
+ def info: (_ToS msg) -> void
77
68
 
78
- def debug: (_ToS msg, ?Array[String?]? prefix) -> void
69
+ def debug: (_ToS msg) -> void
79
70
 
80
71
  def prefix_with: (String? prefix) -> Logger
81
72
 
82
73
  def reopen: () -> void
83
74
 
84
- attr_reader level: Integer
85
-
86
- attr_reader stdout: bool?
87
-
88
- attr_reader sink: Array[Object & _Backend]
89
-
90
- attr_reader names: Array[String?]
75
+ # Protected in Ruby, and called on a copy, so public here
76
+ def add_prefix: (String? prefix) -> Logger
91
77
 
92
78
  private
93
79
 
94
- def settings_from: (Logger | (Object & _Backend) parent, Integer level) -> [Integer, Array[String?], bool?, Array[Object & _Backend]]
95
-
96
80
  def label: (Array[String?] names) -> String?
97
81
 
98
82
  def priority: (Symbol | String level) -> Integer
@@ -1,179 +1,10 @@
1
1
  module Bluepill
2
- # Runs commands for a Process, which is the only class that includes it
3
- module ProcessCommands : _Host
4
- # What ProcessCommands, and the modules it includes, use from Process
5
- interface _Host
6
- include Hooks::_Host
7
-
8
- %a{pure} def children: () -> Array[Process]
9
- %a{pure} def start_command: () -> String?
10
- %a{pure} def stop_command: () -> String?
11
- %a{pure} def restart_command: () -> String?
12
- %a{pure} def stop_signals: () -> Array[Symbol | Integer]?
13
- %a{pure} def start_grace_time: () -> seconds
14
- %a{pure} def stop_grace_time: () -> seconds
15
- %a{pure} def restart_grace_time: () -> seconds
16
- %a{pure} def on_start_timeout: () -> (String | Symbol)
17
- %a{pure} def monitor_children: () -> bool
18
- %a{pure} def uid: () -> String?
19
- %a{pure} def gid: () -> String?
20
- %a{pure} def working_dir: () -> String?
21
- %a{pure} def pid_file: () -> String?
22
- %a{pure} def stdin: () -> String?
23
- %a{pure} def stdout: () -> String?
24
- %a{pure} def stderr: () -> String?
25
- %a{pure} def supplementary_groups: () -> Array[String]?
26
- def daemonize?: () -> bool
27
- def monitor_children?: () -> bool
28
- def clean_threads: () -> void
29
- def signal_process: (Integer | String | Symbol code) -> bool
30
- def unlink_pid: () -> void
31
- def clear_pid: () -> void
32
- def skip_ticks_for: (seconds seconds) -> Integer
33
- def dispatch!: (Symbol | String event, ?String? reason) -> bool
34
- end
35
-
36
- include Execution
37
- include Hooks
38
- include StopSignals
39
-
40
- @threads: Array[Thread]
41
- @stopping_pid: Integer?
42
-
43
- def start_process: () -> Integer
44
-
45
- def run_start_command: (String command) -> void
46
-
47
- def daemonize_process: (String command) -> void
48
-
49
- def stop_process: () -> Integer
50
-
51
- def journal_children: () -> void
52
-
53
- def send_stop: () -> void
54
-
55
- def run_stop_command: (String command) -> void
56
-
57
- def restart_process: () -> Integer
58
-
59
- def run_restart_command: (String command) -> Integer
60
-
61
- def cleanup_process: () -> void
62
- end
63
-
64
- # Stops a Process with its stop_signals, with their delays
65
- module ProcessCommands::StopSignals : ProcessCommands::StopSignals::_Host
66
- # What StopSignals uses from Process
67
- interface _Host
68
- %a{pure} def logger: () -> Logger
69
- %a{pure} def stop_grace_time: () -> seconds
70
- def actual_pid: () -> Integer?
71
- def signal_process: (Integer | String | Symbol code) -> bool
72
- def cleanup_process: () -> void
73
- end
74
-
75
- @threads: Array[Thread]
76
-
77
- def send_stop_signals_in_background: (Array[Symbol | Integer] signals) -> Array[Thread]
78
-
79
- def send_stop_signals: (Array[Symbol | Integer] signals) -> void
80
-
81
- def send_later_stop_signals: (Array[Symbol | Integer] signals) -> seconds?
82
-
83
- def send_stop_signal: (Symbol | Integer signal) -> bool
84
-
85
- def running_after?: (Integer delay) -> bool
86
-
87
- def wait_for_stop: (seconds seconds) -> void
88
- end
89
-
90
- # Runs a Process's commands as its user, in its working_dir, with its
91
- # environment and standard streams
92
- module ProcessCommands::Execution : ProcessCommands::Execution::_Host
93
- # What Execution uses from Process
94
- interface _Host
95
- %a{pure} def logger: () -> Logger
96
- %a{pure} def uid: () -> String?
97
- %a{pure} def gid: () -> String?
98
- %a{pure} def working_dir: () -> String?
99
- %a{pure} def environment: () -> Hash[_ToS, _ToS]?
100
- %a{pure} def pid_file: () -> String?
101
- %a{pure} def stdin: () -> String?
102
- %a{pure} def stdout: () -> String?
103
- %a{pure} def stderr: () -> String?
104
- %a{pure} def supplementary_groups: () -> Array[String]?
105
- def actual_pid: () -> Integer?
106
- def dispatch!: (Symbol | String event, ?String? reason) -> bool
107
- end
108
-
109
- def prepare_command: (String command) -> String
110
-
111
- def substitute_pid: (String command, Integer? pid) -> String
112
-
113
- def system_command_options: () -> System::command_options
114
-
115
- # Runs the block, and dispatches next_state if it takes longer than secs
116
- def with_timeout: [T] (seconds secs, String | Symbol next_state) { (Numeric secs) -> T } -> (T | bool)
117
-
118
- def run_command: (String cmd, String description, ?System::command_options options) -> void
119
- end
120
-
121
- # Runs the commands a Process has around its starts and stops, and on each
122
- # change of state
123
- module ProcessCommands::Hooks : ProcessCommands::Hooks::_Host
124
- # What Hooks uses from Process
125
- interface _Host
126
- %a{pure} def name: () -> String
127
- %a{pure} def logger: () -> Logger
128
- %a{pure} def pre_start_command: () -> String?
129
- %a{pure} def post_start_command: () -> String?
130
- %a{pure} def pre_stop_command: () -> String?
131
- %a{pure} def post_stop_command: () -> String?
132
- %a{pure} def notify_command: () -> String?
133
- %a{pure} def hook_timeout: () -> seconds
134
- %a{pure} def app_name: () -> String?
135
- %a{pure} def group_name: () -> String?
136
- %a{pure} def environment: () -> Hash[_ToS, _ToS]?
137
- def actual_pid: () -> Integer?
138
- def system_command_options: () -> System::command_options
139
- def substitute_pid: (String command, Integer? pid) -> String
140
- def run_command: (String cmd, String description, ?System::command_options options) -> void
141
- end
142
-
143
- @stopping_pid: Integer?
144
- @actual_pid: Integer?
145
- @last_pid: Integer?
146
- @transition_reason: String?
147
-
148
- def pre_start_process: () -> void
149
-
150
- def pre_stop_process: () -> void
151
-
152
- def post_stop_process: () -> Thread?
153
-
154
- def post_start_process: () -> Thread?
155
-
156
- def notify_transition: (_Transition transition) -> Thread?
157
-
158
- def notify_environment: (_Transition transition, Integer? pid) -> Hash[String, String]
159
-
160
- def run_hook_in_background: (String command, String description, Integer? pid, ?Hash[String, String] env) -> Thread
161
-
162
- def run_hook: (String command, String description, Integer? pid, ?Hash[String, String] env) -> void
163
-
164
- def hook_options: (Hash[String, String] env) -> System::command_options
165
-
166
- private
167
-
168
- attr_reader stopping_pid: Integer?
169
-
170
- attr_reader transition_reason: String?
171
-
172
- def cached_pid: () -> Integer?
173
- end
174
-
175
2
  # A monitored process
176
3
  class Process
4
+ # The checks a process is made with: each check's name and options, as
5
+ # a Hash or as a list of pairs, which can name a check twice
6
+ type checks = _Each[[Symbol, Hash[Symbol, untyped]]]
7
+
177
8
  include ProcessCommands
178
9
  include Attributes
179
10
  include Pid
@@ -184,7 +15,7 @@ module Bluepill
184
15
 
185
16
  attr_accessor name: String
186
17
  attr_reader watches: Process::Watches
187
- attr_accessor triggers: Array[Trigger]
18
+ attr_reader triggers: Process::Triggers
188
19
  attr_accessor skip_ticks_until: Integer?
189
20
  attr_accessor process_running: bool?
190
21
 
@@ -213,20 +44,18 @@ module Bluepill
213
44
 
214
45
  # Methods bluepill defines
215
46
 
216
- def initialize: (String process_name, Hash[Symbol, Hash[Symbol, untyped]] checks, ?Hash[Symbol, untyped] options) -> void
47
+ def initialize: (String process_name, checks checks, ?logger: untyped, ?actual_pid: Integer?, **untyped attributes) -> void
217
48
 
218
49
  # Runs the state machine's tick event, then the watches and children
219
50
  def tick: () -> void
220
51
 
221
52
  def tick_children: () -> void
222
53
 
223
- def logger=: (Logger logger) -> void
224
-
225
- def dispatch!: (Symbol | String event, ?String? reason) -> bool
54
+ def dispatch!: (Symbol event, ?String? reason) -> bool
226
55
 
227
- def add_checks: (Hash[Symbol, Hash[Symbol, untyped]] checks, Logger logger) -> void
56
+ def add_checks: (checks checks, Logger logger) -> void
228
57
 
229
- def add_trigger: (Symbol name, Hash[Symbol, untyped] options) -> Array[Trigger]
58
+ def add_check: (Symbol name, Hash[Symbol, untyped] options) -> void
230
59
 
231
60
  # Runs the watches that are due, and dispatches their events
232
61
  def run_watches: () -> void
@@ -240,109 +69,6 @@ module Bluepill
240
69
  def skipping_ticks?: () -> bool?
241
70
  end
242
71
 
243
- # The options a config can set for a Process, and their defaults
244
- module Process::Attributes
245
- CONFIGURABLE_ATTRIBUTES: Array[Symbol]
246
-
247
- attr_accessor pre_start_command: String?
248
- attr_accessor start_command: String?
249
- attr_accessor stop_command: String?
250
- attr_accessor restart_command: String?
251
- attr_accessor stdout: String?
252
- attr_accessor stderr: String?
253
- attr_accessor stdin: String?
254
- attr_accessor daemonize: bool?
255
- attr_accessor pid_file: String?
256
- attr_accessor working_dir: String?
257
- attr_accessor environment: Hash[_ToS, _ToS]?
258
- attr_accessor start_grace_time: seconds
259
- attr_accessor stop_grace_time: seconds
260
- attr_accessor restart_grace_time: seconds
261
- attr_accessor uid: String?
262
- attr_accessor gid: String?
263
- attr_accessor cache_actual_pid: bool
264
- attr_accessor monitor_children: bool
265
- attr_accessor child_process_factory: ProcessFactory?
266
- attr_accessor pid_command: String?
267
- attr_accessor auto_start: bool?
268
- attr_accessor supplementary_groups: Array[String]?
269
- # Signal names alternating with delays in seconds
270
- attr_accessor stop_signals: Array[Symbol | Integer]?
271
- attr_accessor on_start_timeout: String | Symbol
272
- attr_accessor post_start_command: String?
273
- attr_accessor pre_stop_command: String?
274
- attr_accessor post_stop_command: String?
275
- attr_accessor notify_command: String?
276
- attr_accessor hook_timeout: seconds
277
- attr_accessor group_start_noblock: bool
278
- attr_accessor group_restart_noblock: bool
279
- attr_accessor group_stop_noblock: bool
280
- attr_accessor group_unmonitor_noblock: bool
281
-
282
- def configure: (Hash[Symbol, untyped] options) -> void
283
-
284
- def apply_defaults: () -> void
285
- end
286
-
287
- # Finds, signals and forgets a Process's pid
288
- module Process::Pid : Process::Pid::_Host
289
- # What Pid uses from Process
290
- interface _Host
291
- %a{pure} def name: () -> String
292
- %a{pure} def logger: () -> Logger
293
- %a{pure} def pid_file: () -> String?
294
- %a{pure} def pid_command: () -> String?
295
- end
296
-
297
- @process_running: bool?
298
- @cache_actual_pid: bool
299
- @actual_pid: Integer?
300
- @last_pid: Integer?
301
-
302
- def process_running?: (?bool force) -> bool
303
-
304
- def signal_process: (Integer | String | Symbol code) -> bool
305
-
306
- def cache_actual_pid?: () -> bool
307
-
308
- def actual_pid: () -> Integer?
309
-
310
- def pid_from_file: () -> Integer?
311
-
312
- def pid_from_command: () -> Integer?
313
-
314
- def positive_pid: (Integer pid) -> Integer?
315
-
316
- def actual_pid=: (Integer pid) -> void
317
-
318
- def clear_pid: () -> nil
319
-
320
- def unlink_pid: () -> void
321
- end
322
-
323
- # Keeps a Process for each of a Process's children, when it monitors them
324
- module Process::Children : Process::Children::_Host
325
- # What Children uses from Process
326
- interface _Host
327
- %a{pure} def name: () -> String
328
- %a{pure} def logger: () -> Logger
329
- %a{pure} def monitor_children: () -> bool
330
- %a{pure} def child_process_factory: () -> ProcessFactory?
331
- def daemonize?: () -> bool
332
- def actual_pid: () -> Integer?
333
- end
334
-
335
- @children: Array[Process]
336
-
337
- def monitor_children?: () -> bool
338
-
339
- def refresh_children!: () -> void
340
-
341
- def add_children: (Array[Integer] child_pids) -> void
342
-
343
- def new_child: (ProcessFactory factory, Integer child_pid) -> Process
344
- end
345
-
346
72
  # Moves a Process between its states
347
73
  module Process::StateMachine : Process::StateMachine::_Host
348
74
  # What StateMachine uses from Process
@@ -375,14 +101,6 @@ module Bluepill
375
101
 
376
102
  def restarting?: () -> bool
377
103
 
378
- def start: () -> bool
379
-
380
- def stop: () -> bool
381
-
382
- def unmonitor: () -> bool
383
-
384
- def restart: () -> bool
385
-
386
104
  # Moves the process to the state an event leads to, and returns whether
387
105
  # it moved
388
106
  def fire_event: (Symbol event) -> bool
@@ -398,7 +116,7 @@ module Bluepill
398
116
  interface _Host
399
117
  %a{pure} def logger: () -> Logger
400
118
  %a{pure} def watches: () -> Process::Watches
401
- %a{pure} def triggers: () -> Array[Trigger]
119
+ %a{pure} def triggers: () -> Process::Triggers
402
120
  %a{pure} def children: () -> Array[Process]
403
121
  def monitor_children?: () -> bool
404
122
  def clean_threads: () -> void
@@ -412,13 +130,12 @@ module Bluepill
412
130
  STARTS: Array[Symbol]
413
131
 
414
132
  @transitioned: bool
133
+ @triggers: Process::Triggers
415
134
 
416
135
  def before_transition: (Process::Transition transition) -> true
417
136
 
418
137
  def after_transition: (Process::Transition transition) -> void
419
138
 
420
- def notify_triggers: (_Transition transition) -> void
421
-
422
139
  def record_transition: (_Transition transition) -> void
423
140
  end
424
141
 
@@ -433,16 +150,14 @@ module Bluepill
433
150
 
434
151
  @watches: Array[ConditionWatch]
435
152
 
436
- def initialize: () -> void
153
+ def initialize: (logger: Logger) -> void
437
154
 
438
- def add: (Symbol name, Hash[Symbol, untyped] options) -> Process::Watches
155
+ def add: (Symbol name, **untyped options) -> Process::Watches
439
156
 
440
157
  def <<: (ConditionWatch watch) -> Process::Watches
441
158
 
442
159
  def each: () { (ConditionWatch watch) -> void } -> Array[ConditionWatch]
443
160
 
444
- def logger=: (Logger logger) -> void
445
-
446
161
  def clear_history!: () -> void
447
162
 
448
163
  # Yields for the process's pid on each due watch's thread
@@ -453,14 +168,35 @@ module Bluepill
453
168
  def events: (Array[[ConditionWatch, Thread]] threads) -> Array[[Symbol, String]]
454
169
  end
455
170
 
171
+ # The triggers a Process tells of its transitions
172
+ class Process::Triggers
173
+ include Enumerable[Trigger]
174
+
175
+ attr_reader logger: Logger
176
+
177
+ @triggers: Array[Trigger]
178
+
179
+ def initialize: (logger: Logger) -> void
180
+
181
+ def add: (Class klass, Process process, **untyped options) -> Process::Triggers
182
+
183
+ def <<: (Trigger trigger) -> Process::Triggers
184
+
185
+ def each: () { (Trigger trigger) -> void } -> Array[Trigger]
186
+
187
+ def notify: (_Transition transition) -> Array[Trigger]
188
+
189
+ def reset!: () -> Array[Trigger]
190
+ end
191
+
456
192
  # Carries out the commands a user gives a Process from the command line
457
193
  module Process::UserCommands : Process::UserCommands::_Host
458
194
  # What UserCommands uses from Process
459
195
  interface _Host
460
196
  %a{pure} def logger: () -> Logger
461
- %a{pure} def triggers: () -> Array[Trigger]
197
+ %a{pure} def triggers: () -> Process::Triggers
462
198
  def process_running?: (?bool force) -> bool
463
- def dispatch!: (Symbol | String event, ?String? reason) -> bool
199
+ def dispatch!: (Symbol event, ?String? reason) -> bool
464
200
  def stop_process: () -> Integer
465
201
  def restart_process: () -> Integer
466
202
  end
@@ -478,7 +214,7 @@ module Bluepill
478
214
 
479
215
  # Keeps a short history of a process's events
480
216
  class ProcessStatistics
481
- type event = [Symbol | String, String?, Time]
217
+ type event = [Symbol, String?, Time]
482
218
 
483
219
  STRFTIME: String
484
220
  EVENTS_TO_PERSIST: Integer
@@ -487,7 +223,7 @@ module Bluepill
487
223
 
488
224
  def initialize: () -> void
489
225
 
490
- def record_event: (Symbol | String event, String? reason) -> Util::RotationalArray[event]
226
+ def record_event: (Symbol event, String? reason) -> Util::RotationalArray[event]
491
227
 
492
228
  def to_s: () -> String
493
229
  end
@@ -498,12 +234,10 @@ module Bluepill
498
234
  attr_accessor name: String?
499
235
  attr_accessor processes: Array[Process]
500
236
  attr_accessor logger: Logger
501
- # Not used by bluepill
502
- attr_accessor process_logger: untyped
503
237
 
504
238
  NOBLOCK: Hash[Symbol, Symbol]
505
239
 
506
- def initialize: (String? name, ?{ ?logger: Logger } options) -> void
240
+ def initialize: (String? name, ?logger: untyped) -> void
507
241
 
508
242
  def add_process: (Process process) -> Array[Process]
509
243