lepus 0.0.1.beta2

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 (60) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/specs.yml +44 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +35 -0
  6. data/.tool-versions +1 -0
  7. data/CHANGELOG.md +10 -0
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +120 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +213 -0
  12. data/Rakefile +4 -0
  13. data/bin/console +9 -0
  14. data/bin/setup +7 -0
  15. data/docker-compose.yml +8 -0
  16. data/exec/lepus +9 -0
  17. data/gemfiles/rails52.gemfile +5 -0
  18. data/gemfiles/rails52.gemfile.lock +242 -0
  19. data/gemfiles/rails61.gemfile +5 -0
  20. data/gemfiles/rails61.gemfile.lock +260 -0
  21. data/lepus.gemspec +53 -0
  22. data/lib/lepus/app_executor.rb +19 -0
  23. data/lib/lepus/cli.rb +27 -0
  24. data/lib/lepus/configuration.rb +90 -0
  25. data/lib/lepus/consumer.rb +177 -0
  26. data/lib/lepus/consumer_config.rb +149 -0
  27. data/lib/lepus/consumer_wrapper.rb +46 -0
  28. data/lib/lepus/lifecycle_hooks.rb +49 -0
  29. data/lib/lepus/message.rb +37 -0
  30. data/lib/lepus/middleware.rb +18 -0
  31. data/lib/lepus/middlewares/honeybadger.rb +23 -0
  32. data/lib/lepus/middlewares/json.rb +35 -0
  33. data/lib/lepus/middlewares/max_retry.rb +57 -0
  34. data/lib/lepus/primitive/string.rb +55 -0
  35. data/lib/lepus/process.rb +136 -0
  36. data/lib/lepus/process_registry.rb +37 -0
  37. data/lib/lepus/processes/base.rb +50 -0
  38. data/lib/lepus/processes/callbacks.rb +72 -0
  39. data/lib/lepus/processes/consumer.rb +113 -0
  40. data/lib/lepus/processes/interruptible.rb +38 -0
  41. data/lib/lepus/processes/procline.rb +11 -0
  42. data/lib/lepus/processes/registrable.rb +67 -0
  43. data/lib/lepus/processes/runnable.rb +102 -0
  44. data/lib/lepus/processes/supervised.rb +44 -0
  45. data/lib/lepus/processes.rb +6 -0
  46. data/lib/lepus/producer.rb +42 -0
  47. data/lib/lepus/rails/log_subscriber.rb +120 -0
  48. data/lib/lepus/rails/railtie.rb +31 -0
  49. data/lib/lepus/rails.rb +7 -0
  50. data/lib/lepus/supervisor/config.rb +45 -0
  51. data/lib/lepus/supervisor/maintenance.rb +35 -0
  52. data/lib/lepus/supervisor/pidfile.rb +61 -0
  53. data/lib/lepus/supervisor/pidfiled.rb +29 -0
  54. data/lib/lepus/supervisor/signals.rb +71 -0
  55. data/lib/lepus/supervisor.rb +204 -0
  56. data/lib/lepus/timer.rb +29 -0
  57. data/lib/lepus/version.rb +5 -0
  58. data/lib/lepus.rb +95 -0
  59. data/lib/puma/plugin/lepus.rb +74 -0
  60. metadata +290 -0
@@ -0,0 +1,242 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ lepus (0.0.1.beta2)
5
+ bunny
6
+ concurrent-ruby
7
+ multi_json
8
+ thor
9
+ zeitwerk
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ actioncable (5.2.8.1)
15
+ actionpack (= 5.2.8.1)
16
+ nio4r (~> 2.0)
17
+ websocket-driver (>= 0.6.1)
18
+ actionmailer (5.2.8.1)
19
+ actionpack (= 5.2.8.1)
20
+ actionview (= 5.2.8.1)
21
+ activejob (= 5.2.8.1)
22
+ mail (~> 2.5, >= 2.5.4)
23
+ rails-dom-testing (~> 2.0)
24
+ actionpack (5.2.8.1)
25
+ actionview (= 5.2.8.1)
26
+ activesupport (= 5.2.8.1)
27
+ rack (~> 2.0, >= 2.0.8)
28
+ rack-test (>= 0.6.3)
29
+ rails-dom-testing (~> 2.0)
30
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
31
+ actionview (5.2.8.1)
32
+ activesupport (= 5.2.8.1)
33
+ builder (~> 3.1)
34
+ erubi (~> 1.4)
35
+ rails-dom-testing (~> 2.0)
36
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
37
+ activejob (5.2.8.1)
38
+ activesupport (= 5.2.8.1)
39
+ globalid (>= 0.3.6)
40
+ activemodel (5.2.8.1)
41
+ activesupport (= 5.2.8.1)
42
+ activerecord (5.2.8.1)
43
+ activemodel (= 5.2.8.1)
44
+ activesupport (= 5.2.8.1)
45
+ arel (>= 9.0)
46
+ activestorage (5.2.8.1)
47
+ actionpack (= 5.2.8.1)
48
+ activerecord (= 5.2.8.1)
49
+ marcel (~> 1.0.0)
50
+ activesupport (5.2.8.1)
51
+ concurrent-ruby (~> 1.0, >= 1.0.2)
52
+ i18n (>= 0.7, < 2)
53
+ minitest (~> 5.1)
54
+ tzinfo (~> 1.1)
55
+ addressable (2.8.7)
56
+ public_suffix (>= 2.0.2, < 7.0)
57
+ amq-protocol (2.3.2)
58
+ arel (9.0.0)
59
+ ast (2.4.2)
60
+ bigdecimal (3.1.8)
61
+ builder (3.3.0)
62
+ bunny (2.23.0)
63
+ amq-protocol (~> 2.3, >= 2.3.1)
64
+ sorted_set (~> 1, >= 1.0.2)
65
+ coderay (1.1.3)
66
+ concurrent-ruby (1.3.4)
67
+ crack (1.0.0)
68
+ bigdecimal
69
+ rexml
70
+ crass (1.0.6)
71
+ date (3.3.4)
72
+ diff-lcs (1.5.1)
73
+ dotenv (2.8.1)
74
+ erubi (1.13.0)
75
+ globalid (1.1.0)
76
+ activesupport (>= 5.0)
77
+ hashdiff (1.1.1)
78
+ i18n (1.14.6)
79
+ concurrent-ruby (~> 1.0)
80
+ json (2.7.5)
81
+ language_server-protocol (3.17.0.3)
82
+ lint_roller (1.1.0)
83
+ loofah (2.23.1)
84
+ crass (~> 1.0.2)
85
+ nokogiri (>= 1.12.0)
86
+ mail (2.8.1)
87
+ mini_mime (>= 0.1.1)
88
+ net-imap
89
+ net-pop
90
+ net-smtp
91
+ marcel (1.0.4)
92
+ method_source (1.1.0)
93
+ mini_mime (1.1.5)
94
+ mini_portile2 (2.8.8)
95
+ minitest (5.25.1)
96
+ multi_json (1.15.0)
97
+ net-imap (0.4.17)
98
+ date
99
+ net-protocol
100
+ net-pop (0.1.2)
101
+ net-protocol
102
+ net-protocol (0.2.2)
103
+ timeout
104
+ net-smtp (0.5.0)
105
+ net-protocol
106
+ nio4r (2.7.4)
107
+ nokogiri (1.15.6)
108
+ mini_portile2 (~> 2.8.2)
109
+ racc (~> 1.4)
110
+ nokogiri (1.15.6-x86_64-linux)
111
+ racc (~> 1.4)
112
+ parallel (1.26.3)
113
+ parser (3.3.5.0)
114
+ ast (~> 2.4.1)
115
+ racc
116
+ pry (0.14.2)
117
+ coderay (~> 1.1)
118
+ method_source (~> 1.0)
119
+ public_suffix (5.1.1)
120
+ racc (1.8.1)
121
+ rack (2.2.10)
122
+ rack-test (2.1.0)
123
+ rack (>= 1.3)
124
+ rails (5.2.8.1)
125
+ actioncable (= 5.2.8.1)
126
+ actionmailer (= 5.2.8.1)
127
+ actionpack (= 5.2.8.1)
128
+ actionview (= 5.2.8.1)
129
+ activejob (= 5.2.8.1)
130
+ activemodel (= 5.2.8.1)
131
+ activerecord (= 5.2.8.1)
132
+ activestorage (= 5.2.8.1)
133
+ activesupport (= 5.2.8.1)
134
+ bundler (>= 1.3.0)
135
+ railties (= 5.2.8.1)
136
+ sprockets-rails (>= 2.0.0)
137
+ rails-dom-testing (2.2.0)
138
+ activesupport (>= 5.0.0)
139
+ minitest
140
+ nokogiri (>= 1.6)
141
+ rails-html-sanitizer (1.6.0)
142
+ loofah (~> 2.21)
143
+ nokogiri (~> 1.14)
144
+ railties (5.2.8.1)
145
+ actionpack (= 5.2.8.1)
146
+ activesupport (= 5.2.8.1)
147
+ method_source
148
+ rake (>= 0.8.7)
149
+ thor (>= 0.19.0, < 2.0)
150
+ rainbow (3.1.1)
151
+ rake (13.2.1)
152
+ rbtree (0.4.6)
153
+ regexp_parser (2.9.2)
154
+ rexml (3.3.9)
155
+ rspec (3.13.0)
156
+ rspec-core (~> 3.13.0)
157
+ rspec-expectations (~> 3.13.0)
158
+ rspec-mocks (~> 3.13.0)
159
+ rspec-core (3.13.2)
160
+ rspec-support (~> 3.13.0)
161
+ rspec-expectations (3.13.3)
162
+ diff-lcs (>= 1.2.0, < 2.0)
163
+ rspec-support (~> 3.13.0)
164
+ rspec-mocks (3.13.2)
165
+ diff-lcs (>= 1.2.0, < 2.0)
166
+ rspec-support (~> 3.13.0)
167
+ rspec-support (3.13.1)
168
+ rubocop (1.64.1)
169
+ json (~> 2.3)
170
+ language_server-protocol (>= 3.17.0)
171
+ parallel (~> 1.10)
172
+ parser (>= 3.3.0.2)
173
+ rainbow (>= 2.2.2, < 4.0)
174
+ regexp_parser (>= 1.8, < 3.0)
175
+ rexml (>= 3.2.5, < 4.0)
176
+ rubocop-ast (>= 1.31.1, < 2.0)
177
+ ruby-progressbar (~> 1.7)
178
+ unicode-display_width (>= 2.4.0, < 3.0)
179
+ rubocop-ast (1.33.0)
180
+ parser (>= 3.3.1.0)
181
+ rubocop-performance (1.21.1)
182
+ rubocop (>= 1.48.1, < 2.0)
183
+ rubocop-ast (>= 1.31.1, < 2.0)
184
+ rubocop-rspec (3.2.0)
185
+ rubocop (~> 1.61)
186
+ ruby-progressbar (1.13.0)
187
+ set (1.0.4)
188
+ sorted_set (1.0.3)
189
+ rbtree
190
+ set (~> 1.0)
191
+ sprockets (4.2.1)
192
+ concurrent-ruby (~> 1.0)
193
+ rack (>= 2.2.4, < 4)
194
+ sprockets-rails (3.4.2)
195
+ actionpack (>= 5.2)
196
+ activesupport (>= 5.2)
197
+ sprockets (>= 3.0.0)
198
+ standard (1.37.0)
199
+ language_server-protocol (~> 3.17.0.2)
200
+ lint_roller (~> 1.0)
201
+ rubocop (~> 1.64.0)
202
+ standard-custom (~> 1.0.0)
203
+ standard-performance (~> 1.4)
204
+ standard-custom (1.0.2)
205
+ lint_roller (~> 1.0)
206
+ rubocop (~> 1.50)
207
+ standard-performance (1.4.0)
208
+ lint_roller (~> 1.1)
209
+ rubocop-performance (~> 1.21.0)
210
+ thor (1.3.2)
211
+ thread_safe (0.3.6)
212
+ timeout (0.4.1)
213
+ tzinfo (1.2.11)
214
+ thread_safe (~> 0.1)
215
+ unicode-display_width (2.6.0)
216
+ webmock (3.24.0)
217
+ addressable (>= 2.8.0)
218
+ crack (>= 0.3.2)
219
+ hashdiff (>= 0.4.0, < 2.0.0)
220
+ websocket-driver (0.7.6)
221
+ websocket-extensions (>= 0.1.0)
222
+ websocket-extensions (0.1.5)
223
+ zeitwerk (2.6.18)
224
+
225
+ PLATFORMS
226
+ ruby
227
+ x86_64-linux
228
+
229
+ DEPENDENCIES
230
+ dotenv
231
+ lepus!
232
+ pry
233
+ rails (~> 5.2, >= 5.2.8.1)
234
+ rspec
235
+ rubocop
236
+ rubocop-performance
237
+ rubocop-rspec
238
+ standard
239
+ webmock
240
+
241
+ BUNDLED WITH
242
+ 2.3.22
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: ".."
4
+
5
+ gem "rails", "~> 6.1", ">= 6.1.7.10"
@@ -0,0 +1,260 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ lepus (0.0.1.beta2)
5
+ bunny
6
+ concurrent-ruby
7
+ multi_json
8
+ thor
9
+ zeitwerk
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ actioncable (6.1.7.10)
15
+ actionpack (= 6.1.7.10)
16
+ activesupport (= 6.1.7.10)
17
+ nio4r (~> 2.0)
18
+ websocket-driver (>= 0.6.1)
19
+ actionmailbox (6.1.7.10)
20
+ actionpack (= 6.1.7.10)
21
+ activejob (= 6.1.7.10)
22
+ activerecord (= 6.1.7.10)
23
+ activestorage (= 6.1.7.10)
24
+ activesupport (= 6.1.7.10)
25
+ mail (>= 2.7.1)
26
+ actionmailer (6.1.7.10)
27
+ actionpack (= 6.1.7.10)
28
+ actionview (= 6.1.7.10)
29
+ activejob (= 6.1.7.10)
30
+ activesupport (= 6.1.7.10)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ rails-dom-testing (~> 2.0)
33
+ actionpack (6.1.7.10)
34
+ actionview (= 6.1.7.10)
35
+ activesupport (= 6.1.7.10)
36
+ rack (~> 2.0, >= 2.0.9)
37
+ rack-test (>= 0.6.3)
38
+ rails-dom-testing (~> 2.0)
39
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
40
+ actiontext (6.1.7.10)
41
+ actionpack (= 6.1.7.10)
42
+ activerecord (= 6.1.7.10)
43
+ activestorage (= 6.1.7.10)
44
+ activesupport (= 6.1.7.10)
45
+ nokogiri (>= 1.8.5)
46
+ actionview (6.1.7.10)
47
+ activesupport (= 6.1.7.10)
48
+ builder (~> 3.1)
49
+ erubi (~> 1.4)
50
+ rails-dom-testing (~> 2.0)
51
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
52
+ activejob (6.1.7.10)
53
+ activesupport (= 6.1.7.10)
54
+ globalid (>= 0.3.6)
55
+ activemodel (6.1.7.10)
56
+ activesupport (= 6.1.7.10)
57
+ activerecord (6.1.7.10)
58
+ activemodel (= 6.1.7.10)
59
+ activesupport (= 6.1.7.10)
60
+ activestorage (6.1.7.10)
61
+ actionpack (= 6.1.7.10)
62
+ activejob (= 6.1.7.10)
63
+ activerecord (= 6.1.7.10)
64
+ activesupport (= 6.1.7.10)
65
+ marcel (~> 1.0)
66
+ mini_mime (>= 1.1.0)
67
+ activesupport (6.1.7.10)
68
+ concurrent-ruby (~> 1.0, >= 1.0.2)
69
+ i18n (>= 1.6, < 2)
70
+ minitest (>= 5.1)
71
+ tzinfo (~> 2.0)
72
+ zeitwerk (~> 2.3)
73
+ addressable (2.8.7)
74
+ public_suffix (>= 2.0.2, < 7.0)
75
+ amq-protocol (2.3.2)
76
+ ast (2.4.2)
77
+ bigdecimal (3.1.8)
78
+ builder (3.3.0)
79
+ bunny (2.23.0)
80
+ amq-protocol (~> 2.3, >= 2.3.1)
81
+ sorted_set (~> 1, >= 1.0.2)
82
+ coderay (1.1.3)
83
+ concurrent-ruby (1.3.4)
84
+ crack (1.0.0)
85
+ bigdecimal
86
+ rexml
87
+ crass (1.0.6)
88
+ date (3.3.4)
89
+ diff-lcs (1.5.1)
90
+ dotenv (2.8.1)
91
+ erubi (1.13.0)
92
+ globalid (1.2.1)
93
+ activesupport (>= 6.1)
94
+ hashdiff (1.1.1)
95
+ i18n (1.14.6)
96
+ concurrent-ruby (~> 1.0)
97
+ json (2.7.5)
98
+ language_server-protocol (3.17.0.3)
99
+ lint_roller (1.1.0)
100
+ loofah (2.23.1)
101
+ crass (~> 1.0.2)
102
+ nokogiri (>= 1.12.0)
103
+ mail (2.8.1)
104
+ mini_mime (>= 0.1.1)
105
+ net-imap
106
+ net-pop
107
+ net-smtp
108
+ marcel (1.0.4)
109
+ method_source (1.1.0)
110
+ mini_mime (1.1.5)
111
+ mini_portile2 (2.8.8)
112
+ minitest (5.25.1)
113
+ multi_json (1.15.0)
114
+ net-imap (0.4.17)
115
+ date
116
+ net-protocol
117
+ net-pop (0.1.2)
118
+ net-protocol
119
+ net-protocol (0.2.2)
120
+ timeout
121
+ net-smtp (0.5.0)
122
+ net-protocol
123
+ nio4r (2.7.4)
124
+ nokogiri (1.15.6)
125
+ mini_portile2 (~> 2.8.2)
126
+ racc (~> 1.4)
127
+ nokogiri (1.15.6-x86_64-linux)
128
+ racc (~> 1.4)
129
+ parallel (1.26.3)
130
+ parser (3.3.5.0)
131
+ ast (~> 2.4.1)
132
+ racc
133
+ pry (0.14.2)
134
+ coderay (~> 1.1)
135
+ method_source (~> 1.0)
136
+ public_suffix (5.1.1)
137
+ racc (1.8.1)
138
+ rack (2.2.10)
139
+ rack-test (2.1.0)
140
+ rack (>= 1.3)
141
+ rails (6.1.7.10)
142
+ actioncable (= 6.1.7.10)
143
+ actionmailbox (= 6.1.7.10)
144
+ actionmailer (= 6.1.7.10)
145
+ actionpack (= 6.1.7.10)
146
+ actiontext (= 6.1.7.10)
147
+ actionview (= 6.1.7.10)
148
+ activejob (= 6.1.7.10)
149
+ activemodel (= 6.1.7.10)
150
+ activerecord (= 6.1.7.10)
151
+ activestorage (= 6.1.7.10)
152
+ activesupport (= 6.1.7.10)
153
+ bundler (>= 1.15.0)
154
+ railties (= 6.1.7.10)
155
+ sprockets-rails (>= 2.0.0)
156
+ rails-dom-testing (2.2.0)
157
+ activesupport (>= 5.0.0)
158
+ minitest
159
+ nokogiri (>= 1.6)
160
+ rails-html-sanitizer (1.6.0)
161
+ loofah (~> 2.21)
162
+ nokogiri (~> 1.14)
163
+ railties (6.1.7.10)
164
+ actionpack (= 6.1.7.10)
165
+ activesupport (= 6.1.7.10)
166
+ method_source
167
+ rake (>= 12.2)
168
+ thor (~> 1.0)
169
+ rainbow (3.1.1)
170
+ rake (13.2.1)
171
+ rbtree (0.4.6)
172
+ regexp_parser (2.9.2)
173
+ rexml (3.3.9)
174
+ rspec (3.13.0)
175
+ rspec-core (~> 3.13.0)
176
+ rspec-expectations (~> 3.13.0)
177
+ rspec-mocks (~> 3.13.0)
178
+ rspec-core (3.13.2)
179
+ rspec-support (~> 3.13.0)
180
+ rspec-expectations (3.13.3)
181
+ diff-lcs (>= 1.2.0, < 2.0)
182
+ rspec-support (~> 3.13.0)
183
+ rspec-mocks (3.13.2)
184
+ diff-lcs (>= 1.2.0, < 2.0)
185
+ rspec-support (~> 3.13.0)
186
+ rspec-support (3.13.1)
187
+ rubocop (1.64.1)
188
+ json (~> 2.3)
189
+ language_server-protocol (>= 3.17.0)
190
+ parallel (~> 1.10)
191
+ parser (>= 3.3.0.2)
192
+ rainbow (>= 2.2.2, < 4.0)
193
+ regexp_parser (>= 1.8, < 3.0)
194
+ rexml (>= 3.2.5, < 4.0)
195
+ rubocop-ast (>= 1.31.1, < 2.0)
196
+ ruby-progressbar (~> 1.7)
197
+ unicode-display_width (>= 2.4.0, < 3.0)
198
+ rubocop-ast (1.33.0)
199
+ parser (>= 3.3.1.0)
200
+ rubocop-performance (1.21.1)
201
+ rubocop (>= 1.48.1, < 2.0)
202
+ rubocop-ast (>= 1.31.1, < 2.0)
203
+ rubocop-rspec (3.2.0)
204
+ rubocop (~> 1.61)
205
+ ruby-progressbar (1.13.0)
206
+ set (1.0.4)
207
+ sorted_set (1.0.3)
208
+ rbtree
209
+ set (~> 1.0)
210
+ sprockets (4.2.1)
211
+ concurrent-ruby (~> 1.0)
212
+ rack (>= 2.2.4, < 4)
213
+ sprockets-rails (3.5.2)
214
+ actionpack (>= 6.1)
215
+ activesupport (>= 6.1)
216
+ sprockets (>= 3.0.0)
217
+ standard (1.37.0)
218
+ language_server-protocol (~> 3.17.0.2)
219
+ lint_roller (~> 1.0)
220
+ rubocop (~> 1.64.0)
221
+ standard-custom (~> 1.0.0)
222
+ standard-performance (~> 1.4)
223
+ standard-custom (1.0.2)
224
+ lint_roller (~> 1.0)
225
+ rubocop (~> 1.50)
226
+ standard-performance (1.4.0)
227
+ lint_roller (~> 1.1)
228
+ rubocop-performance (~> 1.21.0)
229
+ thor (1.3.2)
230
+ timeout (0.4.1)
231
+ tzinfo (2.0.6)
232
+ concurrent-ruby (~> 1.0)
233
+ unicode-display_width (2.6.0)
234
+ webmock (3.24.0)
235
+ addressable (>= 2.8.0)
236
+ crack (>= 0.3.2)
237
+ hashdiff (>= 0.4.0, < 2.0.0)
238
+ websocket-driver (0.7.6)
239
+ websocket-extensions (>= 0.1.0)
240
+ websocket-extensions (0.1.5)
241
+ zeitwerk (2.6.18)
242
+
243
+ PLATFORMS
244
+ ruby
245
+ x86_64-linux
246
+
247
+ DEPENDENCIES
248
+ dotenv
249
+ lepus!
250
+ pry
251
+ rails (~> 6.1, >= 6.1.7.10)
252
+ rspec
253
+ rubocop
254
+ rubocop-performance
255
+ rubocop-rspec
256
+ standard
257
+ webmock
258
+
259
+ BUNDLED WITH
260
+ 2.3.22
data/lepus.gemspec ADDED
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/lepus/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "lepus"
7
+ spec.version = Lepus::VERSION
8
+ spec.authors = ["Marcos G. Zimmermann"]
9
+ spec.email = ["mgzmaster@gmail.com"]
10
+
11
+ spec.summary = <<~SUMMARY
12
+ RabbitMQ consumers/producer for ruby applications
13
+ SUMMARY
14
+ spec.description = <<~DESCRIPTION
15
+ RabbitMQ consumers/producer for ruby applicationsd
16
+ DESCRIPTION
17
+
18
+ spec.homepage = "https://github.com/marcosgz/lepus"
19
+ spec.license = "MIT"
20
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
21
+
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes." unless spec.respond_to?(:metadata)
23
+
24
+ spec.metadata["homepage_uri"] = spec.homepage
25
+ spec.metadata["bug_tracker_uri"] = "https://github.com/marcosgz/lepus/issues"
26
+ spec.metadata["documentation_uri"] = "https://github.com/marcosgz/lepus"
27
+ spec.metadata["source_code_uri"] = "https://github.com/marcosgz/lepus"
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+
35
+ spec.bindir = "exec"
36
+ spec.executables = spec.files.grep(%r{^exec/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_dependency "bunny", ">= 0.0.0"
40
+ spec.add_dependency "thor", ">= 0.0.0"
41
+ spec.add_dependency "zeitwerk", ">= 0.0.0"
42
+ spec.add_dependency "concurrent-ruby", ">= 0.0.0"
43
+ spec.add_dependency "multi_json", ">= 0.0.0"
44
+
45
+ spec.add_development_dependency "dotenv"
46
+ spec.add_development_dependency "pry"
47
+ spec.add_development_dependency "rspec"
48
+ spec.add_development_dependency "rubocop"
49
+ spec.add_development_dependency "rubocop-performance"
50
+ spec.add_development_dependency "rubocop-rspec"
51
+ spec.add_development_dependency "standard"
52
+ spec.add_development_dependency "webmock"
53
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lepus
4
+ module AppExecutor
5
+ def wrap_in_app_executor(&block)
6
+ if Lepus.config.app_executor
7
+ Lepus.config.app_executor.wrap(&block)
8
+ else
9
+ yield
10
+ end
11
+ end
12
+
13
+ def handle_thread_error(error)
14
+ Lepus.instrument(:thread_error, error: error)
15
+
16
+ Lepus.config.on_thread_error&.call(error)
17
+ end
18
+ end
19
+ end
data/lib/lepus/cli.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "thor"
2
+
3
+ module Lepus
4
+ class CLI < Thor
5
+ method_option :debug, type: :boolean, default: false
6
+ method_option :logfile, type: :string, default: nil
7
+ method_option :pidfile, type: :string, default: nil
8
+ method_option :require_file, type: :string, aliases: "-r", default: nil
9
+
10
+ desc "start FirstConsumer,SecondConsumer ... ,NthConsumer", "Run Consumer"
11
+ default_command :start
12
+
13
+ def start(consumers = "")
14
+ opts = (@options || {}).transform_keys(&:to_sym)
15
+ unless consumers.empty?
16
+ opts[:consumers] = consumers.split(",").map(&:strip)
17
+ end
18
+ if (logfile = opts.delete(:logfile))
19
+ Lepus.logger = Logger.new(logfile)
20
+ end
21
+ if opts.delete(:debug)
22
+ Lepus.logger.level = Logger::DEBUG
23
+ end
24
+ Lepus::Supervisor.start(**opts)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lepus
4
+ # The class representing the global {Lepus} configuration.
5
+ class Configuration
6
+ DEFAULT_RABBITMQ_URL = "amqp://guest:guest@localhost:5672"
7
+ DEFAULT_RECOVERY_ATTEMPTS = 10
8
+ DEFAULT_RECOVERY_INTERVAL = 5.0
9
+ DEFAULT_RECOVER_FROM_CONNECTION_CLOSE = true
10
+ DEFAULT_CONSUMERS_DIRECTORY = Pathname.new("app/consumers")
11
+
12
+ # @return [String] the connection string for RabbitMQ.
13
+ attr_accessor :rabbitmq_url
14
+
15
+ # @return [String] the name for the RabbitMQ connection.
16
+ attr_accessor :connection_name
17
+
18
+ # @return [Boolean] if the recover_from_connection_close value is set for the RabbitMQ connection.
19
+ attr_accessor :recover_from_connection_close
20
+
21
+ # @return [Integer] max number of recovery attempts, nil means forever
22
+ attr_accessor :recovery_attempts
23
+
24
+ # @return [Integer] the interval in seconds between network recovery attempts.
25
+ attr_accessor :recovery_interval
26
+
27
+ # @return [Pathname] the directory where the consumers are stored.
28
+ attr_reader :consumers_directory
29
+
30
+ # @return [Class] the Rails executor used to wrap asynchronous operations, defaults to the app executor
31
+ # @see https://guides.rubyonrails.org/threading_and_code_execution.html#executor
32
+ attr_accessor :app_executor
33
+
34
+ # @return [Proc] custom lambda/Proc to call when there's an error within a Lepus thread that takes the exception raised as argument
35
+ attr_accessor :on_thread_error
36
+
37
+ # @return [Integer] the interval in seconds between heartbeats. Default is 60 seconds.
38
+ attr_accessor :process_heartbeat_interval
39
+
40
+ # @return [Integer] the threshold in seconds to consider a process alive. Default is 5 minutes.
41
+ attr_accessor :process_alive_threshold
42
+
43
+ def initialize
44
+ @connection_name = "Lepus (#{Lepus::VERSION})"
45
+ @rabbitmq_url = ENV.fetch("RABBITMQ_URL", DEFAULT_RABBITMQ_URL) || DEFAULT_RABBITMQ_URL
46
+ @recovery_attempts = DEFAULT_RECOVERY_ATTEMPTS
47
+ @recovery_interval = DEFAULT_RECOVERY_INTERVAL
48
+ @recover_from_connection_close = DEFAULT_RECOVER_FROM_CONNECTION_CLOSE
49
+ @consumers_directory = DEFAULT_CONSUMERS_DIRECTORY
50
+ @process_heartbeat_interval = 60
51
+ @process_alive_threshold = 5 * 60
52
+ end
53
+
54
+ def create_connection(suffix: nil)
55
+ kwargs = connection_config
56
+ if suffix && connection_name
57
+ kwargs[:connection_name] = "#{connection_name} #{suffix}"
58
+ end
59
+ ::Bunny
60
+ .new(rabbitmq_url, **kwargs)
61
+ .tap { |conn| conn.start }
62
+ end
63
+
64
+ def consumers_directory=(value)
65
+ @consumers_directory = value.is_a?(Pathname) ? value : Pathname.new(value)
66
+ end
67
+
68
+ protected
69
+
70
+ def connection_config
71
+ {
72
+ connection_name: connection_name,
73
+ recover_from_connection_close: recover_from_connection_close,
74
+ recovery_attempts: recovery_attempts,
75
+ network_recovery_interval: recovery_interval,
76
+ recovery_attempts_exhausted: recovery_attempts_exhausted
77
+ }.compact
78
+ end
79
+
80
+ # @return [Proc, NilClass] Proc that is passed to Bunny’s recovery_attempts_exhausted block.
81
+ def recovery_attempts_exhausted
82
+ return unless recovery_attempts
83
+
84
+ proc do
85
+ Thread.current.abort_on_exception = true
86
+ raise Lepus::MaxRecoveryAttemptsExhaustedError
87
+ end
88
+ end
89
+ end
90
+ end