fractor 0.1.4 → 0.1.7

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 (189) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop-https---raw-githubusercontent-com-riboseinc-oss-guides-main-ci-rubocop-yml +552 -0
  3. data/.rubocop.yml +14 -8
  4. data/.rubocop_todo.yml +284 -43
  5. data/README.adoc +111 -950
  6. data/docs/.lycheeignore +16 -0
  7. data/docs/Gemfile +24 -0
  8. data/docs/README.md +157 -0
  9. data/docs/_config.yml +151 -0
  10. data/docs/_features/error-handling.adoc +1192 -0
  11. data/docs/_features/index.adoc +80 -0
  12. data/docs/_features/monitoring.adoc +589 -0
  13. data/docs/_features/signal-handling.adoc +202 -0
  14. data/docs/_features/workflows.adoc +1235 -0
  15. data/docs/_guides/continuous-mode.adoc +736 -0
  16. data/docs/_guides/cookbook.adoc +1133 -0
  17. data/docs/_guides/index.adoc +55 -0
  18. data/docs/_guides/pipeline-mode.adoc +730 -0
  19. data/docs/_guides/troubleshooting.adoc +358 -0
  20. data/docs/_pages/architecture.adoc +1390 -0
  21. data/docs/_pages/core-concepts.adoc +1392 -0
  22. data/docs/_pages/design-principles.adoc +862 -0
  23. data/docs/_pages/getting-started.adoc +290 -0
  24. data/docs/_pages/installation.adoc +143 -0
  25. data/docs/_reference/api.adoc +1080 -0
  26. data/docs/_reference/error-reporting.adoc +670 -0
  27. data/docs/_reference/examples.adoc +181 -0
  28. data/docs/_reference/index.adoc +96 -0
  29. data/docs/_reference/troubleshooting.adoc +862 -0
  30. data/docs/_tutorials/complex-workflows.adoc +1022 -0
  31. data/docs/_tutorials/data-processing-pipeline.adoc +740 -0
  32. data/docs/_tutorials/first-application.adoc +384 -0
  33. data/docs/_tutorials/index.adoc +48 -0
  34. data/docs/_tutorials/long-running-services.adoc +931 -0
  35. data/docs/assets/images/favicon-16.png +0 -0
  36. data/docs/assets/images/favicon-32.png +0 -0
  37. data/docs/assets/images/favicon-48.png +0 -0
  38. data/docs/assets/images/favicon.ico +0 -0
  39. data/docs/assets/images/favicon.png +0 -0
  40. data/docs/assets/images/favicon.svg +45 -0
  41. data/docs/assets/images/fractor-icon.svg +49 -0
  42. data/docs/assets/images/fractor-logo.svg +61 -0
  43. data/docs/index.adoc +131 -0
  44. data/docs/lychee.toml +39 -0
  45. data/examples/api_aggregator/README.adoc +627 -0
  46. data/examples/api_aggregator/api_aggregator.rb +376 -0
  47. data/examples/auto_detection/README.adoc +407 -29
  48. data/examples/auto_detection/auto_detection.rb +9 -9
  49. data/examples/continuous_chat_common/message_protocol.rb +53 -0
  50. data/examples/continuous_chat_fractor/README.adoc +217 -0
  51. data/examples/continuous_chat_fractor/chat_client.rb +303 -0
  52. data/examples/continuous_chat_fractor/chat_common.rb +83 -0
  53. data/examples/continuous_chat_fractor/chat_server.rb +167 -0
  54. data/examples/continuous_chat_fractor/simulate.rb +345 -0
  55. data/examples/continuous_chat_server/README.adoc +135 -0
  56. data/examples/continuous_chat_server/chat_client.rb +303 -0
  57. data/examples/continuous_chat_server/chat_server.rb +359 -0
  58. data/examples/continuous_chat_server/simulate.rb +343 -0
  59. data/examples/error_reporting.rb +207 -0
  60. data/examples/file_processor/README.adoc +170 -0
  61. data/examples/file_processor/file_processor.rb +615 -0
  62. data/examples/file_processor/sample_files/invalid.csv +1 -0
  63. data/examples/file_processor/sample_files/orders.xml +24 -0
  64. data/examples/file_processor/sample_files/products.json +23 -0
  65. data/examples/file_processor/sample_files/users.csv +6 -0
  66. data/examples/hierarchical_hasher/README.adoc +629 -41
  67. data/examples/hierarchical_hasher/hierarchical_hasher.rb +12 -8
  68. data/examples/image_processor/README.adoc +610 -0
  69. data/examples/image_processor/image_processor.rb +349 -0
  70. data/examples/image_processor/processed_images/sample_10_processed.jpg.json +12 -0
  71. data/examples/image_processor/processed_images/sample_1_processed.jpg.json +12 -0
  72. data/examples/image_processor/processed_images/sample_2_processed.jpg.json +12 -0
  73. data/examples/image_processor/processed_images/sample_3_processed.jpg.json +12 -0
  74. data/examples/image_processor/processed_images/sample_4_processed.jpg.json +12 -0
  75. data/examples/image_processor/processed_images/sample_5_processed.jpg.json +12 -0
  76. data/examples/image_processor/processed_images/sample_6_processed.jpg.json +12 -0
  77. data/examples/image_processor/processed_images/sample_7_processed.jpg.json +12 -0
  78. data/examples/image_processor/processed_images/sample_8_processed.jpg.json +12 -0
  79. data/examples/image_processor/processed_images/sample_9_processed.jpg.json +12 -0
  80. data/examples/image_processor/test_images/sample_1.png +1 -0
  81. data/examples/image_processor/test_images/sample_10.png +1 -0
  82. data/examples/image_processor/test_images/sample_2.png +1 -0
  83. data/examples/image_processor/test_images/sample_3.png +1 -0
  84. data/examples/image_processor/test_images/sample_4.png +1 -0
  85. data/examples/image_processor/test_images/sample_5.png +1 -0
  86. data/examples/image_processor/test_images/sample_6.png +1 -0
  87. data/examples/image_processor/test_images/sample_7.png +1 -0
  88. data/examples/image_processor/test_images/sample_8.png +1 -0
  89. data/examples/image_processor/test_images/sample_9.png +1 -0
  90. data/examples/log_analyzer/README.adoc +662 -0
  91. data/examples/log_analyzer/log_analyzer.rb +579 -0
  92. data/examples/log_analyzer/sample_logs/apache.log +20 -0
  93. data/examples/log_analyzer/sample_logs/json.log +15 -0
  94. data/examples/log_analyzer/sample_logs/nginx.log +15 -0
  95. data/examples/log_analyzer/sample_logs/rails.log +29 -0
  96. data/examples/multi_work_type/README.adoc +576 -26
  97. data/examples/multi_work_type/multi_work_type.rb +30 -29
  98. data/examples/performance_monitoring.rb +120 -0
  99. data/examples/pipeline_processing/README.adoc +740 -26
  100. data/examples/pipeline_processing/pipeline_processing.rb +16 -16
  101. data/examples/priority_work_example.rb +155 -0
  102. data/examples/producer_subscriber/README.adoc +889 -46
  103. data/examples/producer_subscriber/producer_subscriber.rb +20 -16
  104. data/examples/scatter_gather/README.adoc +829 -27
  105. data/examples/scatter_gather/scatter_gather.rb +29 -28
  106. data/examples/simple/README.adoc +347 -0
  107. data/examples/simple/sample.rb +5 -5
  108. data/examples/specialized_workers/README.adoc +622 -26
  109. data/examples/specialized_workers/specialized_workers.rb +88 -45
  110. data/examples/stream_processor/README.adoc +206 -0
  111. data/examples/stream_processor/stream_processor.rb +284 -0
  112. data/examples/web_scraper/README.adoc +625 -0
  113. data/examples/web_scraper/web_scraper.rb +285 -0
  114. data/examples/workflow/README.adoc +406 -0
  115. data/examples/workflow/circuit_breaker/README.adoc +360 -0
  116. data/examples/workflow/circuit_breaker/circuit_breaker_workflow.rb +225 -0
  117. data/examples/workflow/conditional/README.adoc +483 -0
  118. data/examples/workflow/conditional/conditional_workflow.rb +215 -0
  119. data/examples/workflow/dead_letter_queue/README.adoc +374 -0
  120. data/examples/workflow/dead_letter_queue/dead_letter_queue_workflow.rb +217 -0
  121. data/examples/workflow/fan_out/README.adoc +381 -0
  122. data/examples/workflow/fan_out/fan_out_workflow.rb +202 -0
  123. data/examples/workflow/retry/README.adoc +248 -0
  124. data/examples/workflow/retry/retry_workflow.rb +195 -0
  125. data/examples/workflow/simple_linear/README.adoc +267 -0
  126. data/examples/workflow/simple_linear/simple_linear_workflow.rb +175 -0
  127. data/examples/workflow/simplified/README.adoc +329 -0
  128. data/examples/workflow/simplified/simplified_workflow.rb +222 -0
  129. data/exe/fractor +10 -0
  130. data/lib/fractor/cli.rb +288 -0
  131. data/lib/fractor/configuration.rb +307 -0
  132. data/lib/fractor/continuous_server.rb +183 -0
  133. data/lib/fractor/error_formatter.rb +72 -0
  134. data/lib/fractor/error_report_generator.rb +152 -0
  135. data/lib/fractor/error_reporter.rb +244 -0
  136. data/lib/fractor/error_statistics.rb +147 -0
  137. data/lib/fractor/execution_tracer.rb +162 -0
  138. data/lib/fractor/logger.rb +230 -0
  139. data/lib/fractor/main_loop_handler.rb +406 -0
  140. data/lib/fractor/main_loop_handler3.rb +135 -0
  141. data/lib/fractor/main_loop_handler4.rb +299 -0
  142. data/lib/fractor/performance_metrics_collector.rb +181 -0
  143. data/lib/fractor/performance_monitor.rb +215 -0
  144. data/lib/fractor/performance_report_generator.rb +202 -0
  145. data/lib/fractor/priority_work.rb +93 -0
  146. data/lib/fractor/priority_work_queue.rb +189 -0
  147. data/lib/fractor/result_aggregator.rb +33 -1
  148. data/lib/fractor/shutdown_handler.rb +168 -0
  149. data/lib/fractor/signal_handler.rb +80 -0
  150. data/lib/fractor/supervisor.rb +430 -144
  151. data/lib/fractor/supervisor_logger.rb +88 -0
  152. data/lib/fractor/version.rb +1 -1
  153. data/lib/fractor/work.rb +12 -0
  154. data/lib/fractor/work_distribution_manager.rb +151 -0
  155. data/lib/fractor/work_queue.rb +88 -0
  156. data/lib/fractor/work_result.rb +181 -9
  157. data/lib/fractor/worker.rb +75 -1
  158. data/lib/fractor/workflow/builder.rb +210 -0
  159. data/lib/fractor/workflow/chain_builder.rb +169 -0
  160. data/lib/fractor/workflow/circuit_breaker.rb +183 -0
  161. data/lib/fractor/workflow/circuit_breaker_orchestrator.rb +208 -0
  162. data/lib/fractor/workflow/circuit_breaker_registry.rb +112 -0
  163. data/lib/fractor/workflow/dead_letter_queue.rb +334 -0
  164. data/lib/fractor/workflow/execution_hooks.rb +39 -0
  165. data/lib/fractor/workflow/execution_strategy.rb +225 -0
  166. data/lib/fractor/workflow/execution_trace.rb +134 -0
  167. data/lib/fractor/workflow/helpers.rb +191 -0
  168. data/lib/fractor/workflow/job.rb +290 -0
  169. data/lib/fractor/workflow/job_dependency_validator.rb +120 -0
  170. data/lib/fractor/workflow/logger.rb +110 -0
  171. data/lib/fractor/workflow/pre_execution_context.rb +193 -0
  172. data/lib/fractor/workflow/retry_config.rb +156 -0
  173. data/lib/fractor/workflow/retry_orchestrator.rb +184 -0
  174. data/lib/fractor/workflow/retry_strategy.rb +93 -0
  175. data/lib/fractor/workflow/structured_logger.rb +30 -0
  176. data/lib/fractor/workflow/type_compatibility_validator.rb +222 -0
  177. data/lib/fractor/workflow/visualizer.rb +211 -0
  178. data/lib/fractor/workflow/workflow_context.rb +132 -0
  179. data/lib/fractor/workflow/workflow_executor.rb +669 -0
  180. data/lib/fractor/workflow/workflow_result.rb +55 -0
  181. data/lib/fractor/workflow/workflow_validator.rb +295 -0
  182. data/lib/fractor/workflow.rb +333 -0
  183. data/lib/fractor/wrapped_ractor.rb +66 -91
  184. data/lib/fractor/wrapped_ractor3.rb +161 -0
  185. data/lib/fractor/wrapped_ractor4.rb +242 -0
  186. data/lib/fractor.rb +93 -3
  187. metadata +192 -6
  188. data/tests/sample.rb.bak +0 -309
  189. data/tests/sample_working.rb.bak +0 -209
@@ -0,0 +1,202 @@
1
+ ---
2
+ layout: default
3
+ title: Signal handling
4
+ nav_order: 3
5
+ ---
6
+ == Signal handling
7
+
8
+ == General
9
+
10
+ Fractor provides production-ready signal handling for process control and monitoring. The framework supports different signals depending on the operating system, enabling graceful shutdown and runtime status monitoring.
11
+
12
+ === Unix signals (Linux, macOS, Unix)
13
+
14
+ ==== SIGINT (Ctrl+C)
15
+
16
+ Interactive interrupt signal for graceful shutdown.
17
+
18
+ Usage:
19
+
20
+ * Press `Ctrl+C` in the terminal running Fractor
21
+ * Behavior depends on mode:
22
+ ** *Batch mode*: Stops immediately after current work completes
23
+ ** *Continuous mode*: Initiates graceful shutdown
24
+
25
+ ==== SIGTERM
26
+
27
+ Standard Unix termination signal, preferred for production deployments.
28
+
29
+ This ensures a graceful shutdown of the Fractor supervisor and its workers.
30
+
31
+ Usage:
32
+
33
+ [source,sh]
34
+ ----
35
+ kill -TERM <pid>
36
+ # or simply
37
+ kill <pid> # SIGTERM is the default
38
+ ----
39
+
40
+ Typical signals from service managers:
41
+
42
+ * Systemd sends SIGTERM on `systemctl stop`
43
+ * Docker sends SIGTERM on `docker stop`
44
+ * Kubernetes sends SIGTERM during pod termination
45
+
46
+ [source,ini]
47
+ ----
48
+ # Example systemd service
49
+ [Service]
50
+ ExecStart=/usr/bin/ruby /path/to/fractor_server.rb
51
+ KillMode=process
52
+ KillSignal=SIGTERM
53
+ TimeoutStopSec=30
54
+ ----
55
+
56
+ ==== SIGUSR1
57
+
58
+ Real-time status monitoring without stopping the process.
59
+
60
+ Usage:
61
+
62
+ [source,sh]
63
+ ----
64
+ kill -USR1 <pid>
65
+ ----
66
+
67
+ Output example:
68
+
69
+ .Status output
70
+ [example]
71
+ ====
72
+ [source]
73
+ ----
74
+ ==== Fractor Supervisor Status ===
75
+ Mode: Continuous
76
+ Running: true
77
+ Workers: 4
78
+ Idle workers: 2
79
+ Queue size: 15
80
+ Results: 127
81
+ Errors: 3
82
+ ----
83
+ ====
84
+
85
+ === Windows signals
86
+
87
+ ==== SIGBREAK (Ctrl+Break)
88
+
89
+ Windows alternative to SIGUSR1 for status monitoring.
90
+
91
+ Usage:
92
+
93
+ * Press `Ctrl+Break` in the terminal running Fractor
94
+ * Same output as SIGUSR1 on Unix
95
+
96
+ [NOTE]
97
+ ====
98
+ SIGUSR1 is not available on Windows. Use `Ctrl+Break` instead for status monitoring on Windows platforms.
99
+ ====
100
+
101
+ === Signal behavior by mode
102
+
103
+ ==== Batch mode
104
+
105
+ In batch processing mode:
106
+
107
+ * SIGINT/SIGTERM: Stops immediately after current work completes
108
+ * SIGUSR1/SIGBREAK: Displays current status
109
+
110
+ ==== Continuous mode
111
+
112
+ In continuous mode (long-running servers):
113
+
114
+ * SIGINT/SIGTERM: Graceful shutdown within ~2 seconds
115
+ ** Stops accepting new work
116
+ ** Completes in-progress work
117
+ ** Cleans up resources
118
+ * SIGUSR1/SIGBREAK: Displays current status
119
+
120
+ === Process monitoring and logging
121
+
122
+ ==== Status monitoring and health checks
123
+
124
+ The signals SIGUSR1 (or SIGBREAK on Windows) can be used for health checks.
125
+
126
+ When the signal is received, the supervisor prints its current status to standard output.
127
+
128
+ .Sending the signal
129
+ [example]
130
+ ====
131
+ Unix:
132
+
133
+ [source,sh]
134
+ ----
135
+ # Send SIGUSR1 to the supervisor process
136
+ kill -USR1 <pid>
137
+ ----
138
+
139
+ Windows:
140
+
141
+ [source,sh]
142
+ ----
143
+ # Send SIGBREAK to the supervisor process
144
+ kill -BREAK <pid>
145
+ ----
146
+
147
+ Output:
148
+
149
+ [source]
150
+ ----
151
+ ==== Fractor Supervisor Status ===
152
+ Mode: Continuous
153
+ Running: true
154
+ Workers: 4
155
+ Idle workers: 2
156
+ Queue size: 15
157
+ Results: 127
158
+ Errors: 3
159
+ ----
160
+ ====
161
+
162
+ ==== Logging
163
+
164
+ Fractor supports logging of its operations to a specified log file.
165
+
166
+ For ContinuousServer, pass the `log_file` parameter:
167
+
168
+ [source,ruby]
169
+ ----
170
+ server = Fractor::ContinuousServer.new(
171
+ worker_pools: [{ worker_class: MyWorker }],
172
+ work_queue: work_queue,
173
+ log_file: 'logs/server.log'
174
+ )
175
+ ----
176
+
177
+ For manual Supervisor usage, set the `FRACTOR_LOG_FILE` environment variable before starting your application:
178
+
179
+ [source,sh]
180
+ ----
181
+ export FRACTOR_LOG_FILE=/path/to/logs/server.log
182
+ ruby my_fractor_app.rb
183
+ ----
184
+
185
+ The log file will contain detailed information about the supervisor's operations, including worker activity, work distribution, results, and errors.
186
+
187
+ .Examples of accessing logs
188
+ [example]
189
+ ====
190
+ [source,sh]
191
+ ----
192
+ # Check if server is responsive (Unix/Linux/macOS)
193
+ kill -USR1 <pid> && tail -f /path/to/logs/server.log
194
+
195
+ # Monitor with systemd
196
+ systemctl status fractor-server
197
+ journalctl -u fractor-server -f
198
+
199
+ # Monitor with Docker
200
+ docker logs -f <container_id>
201
+ ----
202
+ ====