bp3-noticed 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1193948dca5bcda90b8e2c1451a75ee2c93e8573175e178214d3c56a1c91f9b
4
- data.tar.gz: 43df9cace6940523d31d82f2a45c75b3f705bbeb13f6580eca7655b2577c644e
3
+ metadata.gz: 17ac709db4d71552e25763221ab6f4ef95211242a1a138458da6a52b1ba84a96
4
+ data.tar.gz: 596bf31f9cf62f4f5c8133e3f5f8aa6808b0ccb95f9f50be16a16dc6d347ca61
5
5
  SHA512:
6
- metadata.gz: d3c2ce7e7dd976b1a2a19f0a5989db81e8b76b9010a4e9bc54e52fc1d6c54e7d0e180f4c12f65774d4741534f947f84ef4d3d807ded7a77fa0fb40a51761b223
7
- data.tar.gz: '09e6152cf5f3b49bc89b8c403cdc395b695ce83f301f7d7c84407ba0452f6f0962dfee93362b1de6f5ae3dfe82dbd9b4ae4fe7bf1407d01dece3dab3bd918c9e'
6
+ metadata.gz: b867d294631f28e7a4f39f0f2c842a166d38c7003504680866a077d4520d861f341a6b38a84785cdfdf8b8923afa348a2de42452e0e194f7d98fba1a1f4afdf2
7
+ data.tar.gz: fb876744be692af0fca93141185804a04434a575a1fcd2188bbdce17ed470d8ce725cc2a64651c87db4b3de6209f5daaf60b0e3c04a4453ebcfb2f475b3bfbdd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2024-07-31
4
+
5
+ - Namespace include and prepend modules
6
+ - Tweaks
7
+
3
8
  ## [0.1.1] - 2024-06-03
4
9
 
5
10
  - Tweaks and documentation
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bp3-noticed (0.1.1)
4
+ bp3-noticed (0.2.0)
5
5
  activesupport (>= 7.1.2, < 8)
6
6
  bp3-action_dispatch (>= 0.1, < 1)
7
7
  bp3-core (>= 0.1, < 1)
@@ -10,35 +10,35 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (7.1.3.3)
14
- actionpack (= 7.1.3.3)
15
- activesupport (= 7.1.3.3)
13
+ actioncable (7.1.3.4)
14
+ actionpack (= 7.1.3.4)
15
+ activesupport (= 7.1.3.4)
16
16
  nio4r (~> 2.0)
17
17
  websocket-driver (>= 0.6.1)
18
18
  zeitwerk (~> 2.6)
19
- actionmailbox (7.1.3.3)
20
- actionpack (= 7.1.3.3)
21
- activejob (= 7.1.3.3)
22
- activerecord (= 7.1.3.3)
23
- activestorage (= 7.1.3.3)
24
- activesupport (= 7.1.3.3)
19
+ actionmailbox (7.1.3.4)
20
+ actionpack (= 7.1.3.4)
21
+ activejob (= 7.1.3.4)
22
+ activerecord (= 7.1.3.4)
23
+ activestorage (= 7.1.3.4)
24
+ activesupport (= 7.1.3.4)
25
25
  mail (>= 2.7.1)
26
26
  net-imap
27
27
  net-pop
28
28
  net-smtp
29
- actionmailer (7.1.3.3)
30
- actionpack (= 7.1.3.3)
31
- actionview (= 7.1.3.3)
32
- activejob (= 7.1.3.3)
33
- activesupport (= 7.1.3.3)
29
+ actionmailer (7.1.3.4)
30
+ actionpack (= 7.1.3.4)
31
+ actionview (= 7.1.3.4)
32
+ activejob (= 7.1.3.4)
33
+ activesupport (= 7.1.3.4)
34
34
  mail (~> 2.5, >= 2.5.4)
35
35
  net-imap
36
36
  net-pop
37
37
  net-smtp
38
38
  rails-dom-testing (~> 2.2)
39
- actionpack (7.1.3.3)
40
- actionview (= 7.1.3.3)
41
- activesupport (= 7.1.3.3)
39
+ actionpack (7.1.3.4)
40
+ actionview (= 7.1.3.4)
41
+ activesupport (= 7.1.3.4)
42
42
  nokogiri (>= 1.8.5)
43
43
  racc
44
44
  rack (>= 2.2.4)
@@ -46,35 +46,35 @@ GEM
46
46
  rack-test (>= 0.6.3)
47
47
  rails-dom-testing (~> 2.2)
48
48
  rails-html-sanitizer (~> 1.6)
49
- actiontext (7.1.3.3)
50
- actionpack (= 7.1.3.3)
51
- activerecord (= 7.1.3.3)
52
- activestorage (= 7.1.3.3)
53
- activesupport (= 7.1.3.3)
49
+ actiontext (7.1.3.4)
50
+ actionpack (= 7.1.3.4)
51
+ activerecord (= 7.1.3.4)
52
+ activestorage (= 7.1.3.4)
53
+ activesupport (= 7.1.3.4)
54
54
  globalid (>= 0.6.0)
55
55
  nokogiri (>= 1.8.5)
56
- actionview (7.1.3.3)
57
- activesupport (= 7.1.3.3)
56
+ actionview (7.1.3.4)
57
+ activesupport (= 7.1.3.4)
58
58
  builder (~> 3.1)
59
59
  erubi (~> 1.11)
60
60
  rails-dom-testing (~> 2.2)
61
61
  rails-html-sanitizer (~> 1.6)
62
- activejob (7.1.3.3)
63
- activesupport (= 7.1.3.3)
62
+ activejob (7.1.3.4)
63
+ activesupport (= 7.1.3.4)
64
64
  globalid (>= 0.3.6)
65
- activemodel (7.1.3.3)
66
- activesupport (= 7.1.3.3)
67
- activerecord (7.1.3.3)
68
- activemodel (= 7.1.3.3)
69
- activesupport (= 7.1.3.3)
65
+ activemodel (7.1.3.4)
66
+ activesupport (= 7.1.3.4)
67
+ activerecord (7.1.3.4)
68
+ activemodel (= 7.1.3.4)
69
+ activesupport (= 7.1.3.4)
70
70
  timeout (>= 0.4.0)
71
- activestorage (7.1.3.3)
72
- actionpack (= 7.1.3.3)
73
- activejob (= 7.1.3.3)
74
- activerecord (= 7.1.3.3)
75
- activesupport (= 7.1.3.3)
71
+ activestorage (7.1.3.4)
72
+ actionpack (= 7.1.3.4)
73
+ activejob (= 7.1.3.4)
74
+ activerecord (= 7.1.3.4)
75
+ activesupport (= 7.1.3.4)
76
76
  marcel (~> 1.0)
77
- activesupport (7.1.3.3)
77
+ activesupport (7.1.3.4)
78
78
  base64
79
79
  bigdecimal
80
80
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -87,28 +87,28 @@ GEM
87
87
  ast (2.4.2)
88
88
  base64 (0.2.0)
89
89
  bigdecimal (3.1.8)
90
- bp3-action_dispatch (0.1.1)
90
+ bp3-action_dispatch (0.1.2)
91
91
  actionpack (>= 7.1.2, < 8)
92
92
  activesupport (>= 7.1.2, < 8)
93
93
  i18n (>= 1.8.11, < 2)
94
- bp3-core (0.1.2)
94
+ bp3-core (0.1.4)
95
95
  actionview (>= 7.1.2, < 8)
96
96
  activesupport (>= 7.1.2, < 8)
97
- builder (3.2.4)
97
+ builder (3.3.0)
98
98
  byebug (11.1.3)
99
- concurrent-ruby (1.3.1)
99
+ concurrent-ruby (1.3.3)
100
100
  connection_pool (2.4.1)
101
101
  crass (1.0.6)
102
102
  date (3.3.4)
103
103
  diff-lcs (1.5.1)
104
104
  drb (2.2.1)
105
- erubi (1.12.0)
105
+ erubi (1.13.0)
106
106
  globalid (1.2.1)
107
107
  activesupport (>= 6.1)
108
108
  i18n (1.14.5)
109
109
  concurrent-ruby (~> 1.0)
110
110
  io-console (0.7.2)
111
- irb (1.13.1)
111
+ irb (1.14.0)
112
112
  rdoc (>= 4.0.0)
113
113
  reline (>= 0.4.2)
114
114
  json (2.7.2)
@@ -123,9 +123,9 @@ GEM
123
123
  net-smtp
124
124
  marcel (1.0.4)
125
125
  mini_mime (1.1.5)
126
- minitest (5.23.1)
126
+ minitest (5.24.1)
127
127
  mutex_m (0.2.0)
128
- net-imap (0.4.12)
128
+ net-imap (0.4.14)
129
129
  date
130
130
  net-protocol
131
131
  net-pop (0.1.2)
@@ -135,18 +135,18 @@ GEM
135
135
  net-smtp (0.5.0)
136
136
  net-protocol
137
137
  nio4r (2.7.3)
138
- nokogiri (1.16.5-x86_64-darwin)
138
+ nokogiri (1.16.7-x86_64-darwin)
139
139
  racc (~> 1.4)
140
- noticed (2.3.2)
140
+ noticed (2.4.1)
141
141
  rails (>= 6.1.0)
142
- parallel (1.24.0)
143
- parser (3.3.2.0)
142
+ parallel (1.25.1)
143
+ parser (3.3.4.0)
144
144
  ast (~> 2.4.1)
145
145
  racc
146
146
  psych (5.1.2)
147
147
  stringio
148
- racc (1.8.0)
149
- rack (3.0.11)
148
+ racc (1.8.1)
149
+ rack (3.1.7)
150
150
  rack-session (2.0.0)
151
151
  rack (>= 3.0.0)
152
152
  rack-test (2.1.0)
@@ -154,20 +154,20 @@ GEM
154
154
  rackup (2.1.0)
155
155
  rack (>= 3)
156
156
  webrick (~> 1.8)
157
- rails (7.1.3.3)
158
- actioncable (= 7.1.3.3)
159
- actionmailbox (= 7.1.3.3)
160
- actionmailer (= 7.1.3.3)
161
- actionpack (= 7.1.3.3)
162
- actiontext (= 7.1.3.3)
163
- actionview (= 7.1.3.3)
164
- activejob (= 7.1.3.3)
165
- activemodel (= 7.1.3.3)
166
- activerecord (= 7.1.3.3)
167
- activestorage (= 7.1.3.3)
168
- activesupport (= 7.1.3.3)
157
+ rails (7.1.3.4)
158
+ actioncable (= 7.1.3.4)
159
+ actionmailbox (= 7.1.3.4)
160
+ actionmailer (= 7.1.3.4)
161
+ actionpack (= 7.1.3.4)
162
+ actiontext (= 7.1.3.4)
163
+ actionview (= 7.1.3.4)
164
+ activejob (= 7.1.3.4)
165
+ activemodel (= 7.1.3.4)
166
+ activerecord (= 7.1.3.4)
167
+ activestorage (= 7.1.3.4)
168
+ activesupport (= 7.1.3.4)
169
169
  bundler (>= 1.15.0)
170
- railties (= 7.1.3.3)
170
+ railties (= 7.1.3.4)
171
171
  rails-dom-testing (2.2.0)
172
172
  activesupport (>= 5.0.0)
173
173
  minitest
@@ -175,9 +175,9 @@ GEM
175
175
  rails-html-sanitizer (1.6.0)
176
176
  loofah (~> 2.21)
177
177
  nokogiri (~> 1.14)
178
- railties (7.1.3.3)
179
- actionpack (= 7.1.3.3)
180
- activesupport (= 7.1.3.3)
178
+ railties (7.1.3.4)
179
+ actionpack (= 7.1.3.4)
180
+ activesupport (= 7.1.3.4)
181
181
  irb
182
182
  rackup (>= 1.0.0)
183
183
  rake (>= 12.2)
@@ -188,51 +188,51 @@ GEM
188
188
  rdoc (6.7.0)
189
189
  psych (>= 4.0.0)
190
190
  regexp_parser (2.9.2)
191
- reline (0.5.8)
191
+ reline (0.5.9)
192
192
  io-console (~> 0.5)
193
- rexml (3.2.8)
194
- strscan (>= 3.0.9)
193
+ rexml (3.3.2)
194
+ strscan
195
195
  rspec (3.13.0)
196
196
  rspec-core (~> 3.13.0)
197
197
  rspec-expectations (~> 3.13.0)
198
198
  rspec-mocks (~> 3.13.0)
199
199
  rspec-core (3.13.0)
200
200
  rspec-support (~> 3.13.0)
201
- rspec-expectations (3.13.0)
201
+ rspec-expectations (3.13.1)
202
202
  diff-lcs (>= 1.2.0, < 2.0)
203
203
  rspec-support (~> 3.13.0)
204
204
  rspec-mocks (3.13.1)
205
205
  diff-lcs (>= 1.2.0, < 2.0)
206
206
  rspec-support (~> 3.13.0)
207
207
  rspec-support (3.13.1)
208
- rubocop (1.64.1)
208
+ rubocop (1.65.0)
209
209
  json (~> 2.3)
210
210
  language_server-protocol (>= 3.17.0)
211
211
  parallel (~> 1.10)
212
212
  parser (>= 3.3.0.2)
213
213
  rainbow (>= 2.2.2, < 4.0)
214
- regexp_parser (>= 1.8, < 3.0)
214
+ regexp_parser (>= 2.4, < 3.0)
215
215
  rexml (>= 3.2.5, < 4.0)
216
216
  rubocop-ast (>= 1.31.1, < 2.0)
217
217
  ruby-progressbar (~> 1.7)
218
218
  unicode-display_width (>= 2.4.0, < 3.0)
219
219
  rubocop-ast (1.31.3)
220
220
  parser (>= 3.3.1.0)
221
- rubocop-capybara (2.20.0)
222
- rubocop (~> 1.41)
223
- rubocop-factory_bot (2.25.1)
221
+ rubocop-capybara (2.21.0)
224
222
  rubocop (~> 1.41)
223
+ rubocop-factory_bot (2.26.1)
224
+ rubocop (~> 1.61)
225
225
  rubocop-rake (0.6.0)
226
226
  rubocop (~> 1.0)
227
- rubocop-rspec (2.30.0)
227
+ rubocop-rspec (2.31.0)
228
228
  rubocop (~> 1.40)
229
229
  rubocop-capybara (~> 2.17)
230
230
  rubocop-factory_bot (~> 2.22)
231
231
  rubocop-rspec_rails (~> 2.28)
232
- rubocop-rspec_rails (2.28.3)
233
- rubocop (~> 1.40)
232
+ rubocop-rspec_rails (2.29.1)
233
+ rubocop (~> 1.61)
234
234
  ruby-progressbar (1.13.0)
235
- stringio (3.1.0)
235
+ stringio (3.1.1)
236
236
  strscan (3.1.0)
237
237
  thor (1.3.1)
238
238
  timeout (0.4.1)
@@ -243,7 +243,7 @@ GEM
243
243
  websocket-driver (0.7.6)
244
244
  websocket-extensions (>= 0.1.0)
245
245
  websocket-extensions (0.1.5)
246
- zeitwerk (2.6.15)
246
+ zeitwerk (2.6.17)
247
247
 
248
248
  PLATFORMS
249
249
  x86_64-darwin-22
@@ -1,69 +1,81 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CommonIncludes
4
- extend ActiveSupport::Concern
3
+ module Bp3
4
+ module Noticed
5
+ module CommonIncludes
6
+ extend ActiveSupport::Concern
5
7
 
6
- included do
7
- attr_reader :args, :kwargs
8
- end
8
+ included do
9
+ attr_reader :args, :kwargs
10
+ end
9
11
 
10
- class_methods do
11
- def global_request_state_class
12
- Bp3::Core::Rqid.global_request_state_class
13
- end
14
- end
12
+ class_methods do
13
+ def global_request_state_class
14
+ Bp3::Core::Rqid.global_request_state_class
15
+ end
16
+ end
15
17
 
16
- def global_request_state_class
17
- Bp3::Core::Rqid.global_request_state_class
18
- end
18
+ def global_request_state_class
19
+ Bp3::Core::Rqid.global_request_state_class
20
+ end
19
21
 
20
- def run(...)
21
- perform(...)
22
- end
22
+ def run(...)
23
+ perform(...)
24
+ end
23
25
 
24
- private
26
+ private
25
27
 
26
- def set_global_request_state
27
- global_request_state_class.from_hash(state)
28
- global_request_state_class.current_site ||= ensure_site
29
- end
28
+ def set_global_request_state
29
+ global_request_state_class.from_hash(state)
30
+ global_request_state_class.current_site ||= ensure_site
31
+ end
30
32
 
31
- def state
32
- run_attrs :state
33
- end
33
+ def state
34
+ run_attrs :state
35
+ end
34
36
 
35
- def ensure_site
36
- id = run_attrs(:sites_site_id) || run_attrs(:site_id)
37
- if id.present?
38
- site = site_class.find_by(id:)
39
- return site if site.present?
37
+ def ensure_site
38
+ id = run_attrs(:sites_site_id) || run_attrs(:site_id)
39
+ if id.present?
40
+ site = site_class.find_by(id:)
41
+ return site if site.present?
40
42
 
41
- message = "Unable to find site #{id}"
42
- include_log_error(key: 'prepend_state.ensure_site', message:)
43
- end
43
+ message = "Unable to find site #{id}"
44
+ include_log_error(key: 'prepend_state.ensure_site', message:)
45
+ end
44
46
 
45
- site_class.root_site || site_class.first
46
- end
47
+ site_class.root_site || site_class.first
48
+ end
47
49
 
48
- def site_class
49
- Bp3::ActionDispatch.site_class
50
- end
50
+ def include_log_error(key:, message:, details: {})
51
+ return log_error(key:, message:, details:) if respond_to?(:log_error, true)
51
52
 
52
- def check(hash_or_array, key)
53
- return nil if hash_or_array.blank?
53
+ message = "Warning: #{self.class.name}#log_info: unable to log error #{key}/#{message}/#{details}"
54
+ Rails.logger.warn { message }
55
+ nil
56
+ end
54
57
 
55
- if hash_or_array.is_a?(Array)
56
- hash_or_array.each do |obj|
57
- value = check(obj, key)
58
- return value if value
58
+ def site_class
59
+ Bp3::ActionDispatch.site_class
60
+ end
61
+
62
+ def check(hash_or_array, key)
63
+ return nil if hash_or_array.blank?
64
+
65
+ if hash_or_array.is_a?(Array)
66
+ hash_or_array.each do |obj|
67
+ value = check(obj, key)
68
+ return value if value
69
+ end
70
+ nil
71
+ elsif hash_or_array.is_a?(Hash)
72
+ hash_or_array[key.to_s] || hash_or_array[key.to_sym]
73
+ end
59
74
  end
60
- nil
61
- elsif hash_or_array.is_a?(Hash)
62
- hash_or_array[key.to_s] || hash_or_array[key.to_sym]
63
- end
64
- end
65
75
 
66
- def job_key
67
- self.class.name.underscore
76
+ def job_key
77
+ self.class.name.underscore
78
+ end
79
+ end
68
80
  end
69
81
  end
@@ -1,70 +1,66 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module JobIncludes
4
- extend ActiveSupport::Concern
3
+ module Bp3
4
+ module Noticed
5
+ module JobIncludes
6
+ extend ActiveSupport::Concern
5
7
 
6
- class_methods do
7
- def enqueue(...)
8
- new.enqueue(...)
9
- end
8
+ class_methods do
9
+ def enqueue(...)
10
+ new.enqueue(...)
11
+ end
10
12
 
11
- def run_now(...)
12
- perform_later(...) # don't use perform_now, as it won't run in the background
13
- end
13
+ def run_now(...)
14
+ perform_later(...) # don't use perform_now, as it won't run in the background
15
+ end
14
16
 
15
- def run_soon(...)
16
- set(wait: 1.minute).perform_later(...)
17
- end
17
+ def run_soon(...)
18
+ set(wait: 1.minute).perform_later(...)
19
+ end
18
20
 
19
- def run_later(...)
20
- set(wait: 1.hour).perform_later(...)
21
- end
22
- end
21
+ def run_later(...)
22
+ set(wait: 1.hour).perform_later(...)
23
+ end
24
+ end
23
25
 
24
- def enqueue(*, **)
25
- # Add state to arguments, not kwargs
26
- # kwargs['state'] = GlobalRequestState.to_hash
27
- arguments << { 'state' => global_request_state_class.to_hash }
28
- super
29
- end
26
+ def enqueue(*, **)
27
+ # Add state to arguments, not kwargs
28
+ # kwargs['state'] = GlobalRequestState.to_hash
29
+ arguments << { 'state' => global_request_state_class.to_hash }
30
+ super
31
+ end
30
32
 
31
- private
33
+ private
32
34
 
33
- def job_type
34
- 'job'
35
- end
35
+ def job_type
36
+ 'job'
37
+ end
36
38
 
37
- def include_log_error(key:, message:, details: {})
38
- return log_error(key:, message:, details:) if respond_to?(:log_error, true)
39
+ def run_attrs(key)
40
+ check(arguments, key)
41
+ end
39
42
 
40
- message = "Warning: #{self.class.name}#log_info: unable to log error #{key}/#{message}/#{details}"
41
- Rails.logger.warn { message }
42
- nil
43
- end
43
+ def check(hash_or_array, key)
44
+ return nil if hash_or_array.blank?
44
45
 
45
- def run_attrs(key)
46
- check(arguments, key)
47
- end
46
+ if hash_or_array.is_a?(Array)
47
+ hash_or_array.each do |obj|
48
+ value = check(obj, key)
49
+ return value if value
50
+ end
51
+ nil
52
+ elsif hash_or_array.is_a?(Hash)
53
+ hash_or_array[key.to_s] || hash_or_array[key.to_sym]
54
+ end
55
+ end
48
56
 
49
- def check(hash_or_array, key)
50
- return nil if hash_or_array.blank?
57
+ def site
58
+ global_request_state_class.current_site
59
+ end
51
60
 
52
- if hash_or_array.is_a?(Array)
53
- hash_or_array.each do |obj|
54
- value = check(obj, key)
55
- return value if value
61
+ def job_key
62
+ self.class.name.underscore
56
63
  end
57
- nil
58
- elsif hash_or_array.is_a?(Hash)
59
- hash_or_array[key.to_s] || hash_or_array[key.to_sym]
60
64
  end
61
65
  end
62
-
63
- def site
64
- global_request_state_class.current_site
65
- end
66
-
67
- def job_key
68
- self.class.name.underscore
69
- end
70
66
  end
@@ -1,74 +1,79 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PrependPerform
4
- include CommonIncludes
3
+ module Bp3
4
+ module Noticed
5
+ module PrependPerform
6
+ include CommonIncludes
5
7
 
6
- # rubocop:disable Metrics/MethodLength
7
- def perform(*args, **kwargs)
8
- @args = args
9
- @kwargs = kwargs
10
- set_global_request_state
11
- details = { args:, kwargs: }
12
- log = nil
13
- args = remove_state(args)
14
- kwargs = remove_state(kwargs)
15
- begin
16
- super
17
- rescue ArgumentError
18
- super() # in case super is relying on run_attrs
19
- end
20
- disposition = 'finished'
21
- log = prepend_log_info(key: "#{job_type}.#{disposition}.#{job_key}", message: "#{disposition} job_type", details:)
22
- rescue StandardError => e
23
- disposition = 'failed'
24
- log = prepend_log_exception(e, key: "#{job_type}.#{disposition}.#{job_key}", details:)
25
- raise e # to continue the normal job flow
26
- ensure
27
- prepend_add_event(eventable: log, disposition:)
28
- global_request_state_class.clear!
29
- end
30
- # rubocop:enable Metrics/MethodLength
8
+ # rubocop:disable Metrics/MethodLength
9
+ def perform(*args, **kwargs)
10
+ @args = args
11
+ @kwargs = kwargs
12
+ set_global_request_state
13
+ details = { args:, kwargs: }
14
+ log = nil
15
+ args = remove_state(args)
16
+ kwargs = remove_state(kwargs)
17
+ begin
18
+ super
19
+ rescue ArgumentError
20
+ super() # in case super is relying on run_attrs
21
+ end
22
+ disposition = 'finished'
23
+ log = prepend_log_info(key: "#{job_type}.#{disposition}.#{job_key}", message: "#{disposition} job_type",
24
+ details:)
25
+ rescue StandardError => e
26
+ disposition = 'failed'
27
+ log = prepend_log_exception(e, key: "#{job_type}.#{disposition}.#{job_key}", details:)
28
+ raise e # to continue the normal job flow
29
+ ensure
30
+ prepend_add_event(eventable: log, disposition:)
31
+ global_request_state_class.clear!
32
+ end
33
+ # rubocop:enable Metrics/MethodLength
31
34
 
32
- private
35
+ private
33
36
 
34
- def remove_state(obj)
35
- if obj.is_a?(Hash)
36
- obj.except(:state, 'state')
37
- elsif obj.is_a?(Array)
38
- obj.reject { |e| e.is_a?(Hash) && (e.key?(:state) || e.key?('state')) }
39
- else
40
- obj
41
- end
42
- end
37
+ def remove_state(obj)
38
+ if obj.is_a?(Hash)
39
+ obj.except(:state, 'state')
40
+ elsif obj.is_a?(Array)
41
+ obj.reject { |e| e.is_a?(Hash) && (e.key?(:state) || e.key?('state')) }
42
+ else
43
+ obj
44
+ end
45
+ end
43
46
 
44
- # override in subclasses if needed
45
- def prepend_add_event(eventable:, disposition:)
46
- return add_event(eventable:, disposition:) if respond_to?(:add_event, true)
47
+ # override in subclasses if needed
48
+ def prepend_add_event(eventable:, disposition:)
49
+ return add_event(eventable:, disposition:) if respond_to?(:add_event, true)
47
50
 
48
- creator = global_request_state_class.current_login || global_request_state_class.current_visitor
49
- who = creator.nil? ? 'nil' : "#{creator.class.name}/#{creator.id}"
50
- did = disposition
51
- what = eventable.nil? ? 'nil' : "#{eventable.class.name}/#{eventable.id}"
52
- message = "Warning: #{self.class.name}#add_event: unable to add event #{who}/#{did}/#{what}"
53
- Rails.logger.warn { message }
54
- nil
55
- end
51
+ creator = global_request_state_class.current_login || global_request_state_class.current_visitor
52
+ who = creator.nil? ? 'nil' : "#{creator.class.name}/#{creator.id}"
53
+ did = disposition
54
+ what = eventable.nil? ? 'nil' : "#{eventable.class.name}/#{eventable.id}"
55
+ message = "Warning: #{self.class.name}#add_event: unable to add event #{who}/#{did}/#{what}"
56
+ Rails.logger.warn { message }
57
+ nil
58
+ end
56
59
 
57
- # override in subclasses if needed
58
- def prepend_log_info(key:, message:, details: {})
59
- return log_info(key:, message:, details:) if respond_to?(:log_info, true)
60
+ # override in subclasses if needed
61
+ def prepend_log_info(key:, message:, details: {})
62
+ return log_info(key:, message:, details:) if respond_to?(:log_info, true)
60
63
 
61
- message = "Warning: #{self.class.name}#log_info: unable to log info #{key}/#{message}/#{details}"
62
- Rails.logger.warn { message }
63
- nil
64
- end
64
+ message = "Warning: #{self.class.name}#log_info: unable to log info #{key}/#{message}/#{details}"
65
+ Rails.logger.warn { message }
66
+ nil
67
+ end
65
68
 
66
- # override in subclasses if needed
67
- def prepend_log_exception(exception, key:, details: {})
68
- return log_exception(exception, key:, details:) if respond_to?(:log_exception, true)
69
+ # override in subclasses if needed
70
+ def prepend_log_exception(exception, key:, details: {})
71
+ return log_exception(exception, key:, details:) if respond_to?(:log_exception, true)
69
72
 
70
- message = "Warning: #{self.class.name}#log_exception: unable to log exception #{exception}/#{key}/#{details}"
71
- Rails.logger.warn { message }
72
- nil
73
+ message = "Warning: #{self.class.name}#log_exception: unable to log exception #{exception}/#{key}/#{details}"
74
+ Rails.logger.warn { message }
75
+ nil
76
+ end
77
+ end
73
78
  end
74
79
  end
@@ -1,61 +1,65 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module QueIncludes
4
- extend ActiveSupport::Concern
5
-
6
- class_methods do
7
- def enqueue(*args, **kwargs)
8
- if ENV.fetch('BP_DEBUG', nil) =~ /quejobs/
9
- Rails.logger.warn { "enqueue with #{args} and #{kwargs}" }
10
- Rails.logger.warn { global_request_state_class.to_hash }
11
- end
12
- kwargs['state'] = global_request_state_class.to_hash
13
- super
14
- end
3
+ module Bp3
4
+ module Noticed
5
+ module QueIncludes
6
+ extend ActiveSupport::Concern
15
7
 
16
- def perform_now(...)
17
- run(...)
18
- end
8
+ class_methods do
9
+ def enqueue(*args, **kwargs)
10
+ if ENV.fetch('BP_DEBUG', nil) =~ /quejobs/
11
+ Rails.logger.warn { "enqueue with #{args} and #{kwargs}" }
12
+ Rails.logger.warn { global_request_state_class.to_hash }
13
+ end
14
+ kwargs['state'] = global_request_state_class.to_hash
15
+ super
16
+ end
19
17
 
20
- def run_now(...)
21
- enqueue(...) # don't use perform_now, as it won't run in the background
22
- end
18
+ def perform_now(...)
19
+ run(...)
20
+ end
23
21
 
24
- def run_soon(*, **kwargs)
25
- kwargs[:job_options] ||= {}
26
- kwargs[:job_options][:run_at] ||= 1.minute.from_now
27
- enqueue(*, **kwargs)
28
- end
22
+ def run_now(...)
23
+ enqueue(...) # don't use perform_now, as it won't run in the background
24
+ end
29
25
 
30
- def run_later(*, **kwargs)
31
- kwargs[:job_options] ||= {}
32
- kwargs[:job_options][:run_at] ||= 1.hour.from_now
33
- enqueue(*, **kwargs)
34
- end
35
- end
26
+ def run_soon(*, **kwargs)
27
+ kwargs[:job_options] ||= {}
28
+ kwargs[:job_options][:run_at] ||= 1.minute.from_now
29
+ enqueue(*, **kwargs)
30
+ end
36
31
 
37
- # set the log level based on the job duration. elapsed is in seconds
38
- def log_level(elapsed)
39
- if elapsed > 5
40
- :warn
41
- elsif elapsed > 1
42
- :info
43
- else
44
- false # no need to log
45
- end
46
- end
32
+ def run_later(*, **kwargs)
33
+ kwargs[:job_options] ||= {}
34
+ kwargs[:job_options][:run_at] ||= 1.hour.from_now
35
+ enqueue(*, **kwargs)
36
+ end
37
+ end
47
38
 
48
- private
39
+ # set the log level based on the job duration. elapsed is in seconds
40
+ def log_level(elapsed)
41
+ if elapsed > 5
42
+ :warn
43
+ elsif elapsed > 1
44
+ :info
45
+ else
46
+ false # no need to log
47
+ end
48
+ end
49
49
 
50
- def job_type
51
- 'que'
52
- end
50
+ private
53
51
 
54
- def run_attrs(key)
55
- check(que_attrs, key) ||
56
- check(que_attrs[:args], key) ||
57
- check(que_attrs[:kwargs], key) ||
58
- check(args, key) ||
59
- check(kwargs, key)
52
+ def job_type
53
+ 'que'
54
+ end
55
+
56
+ def run_attrs(key)
57
+ check(que_attrs, key) ||
58
+ check(que_attrs[:args], key) ||
59
+ check(que_attrs[:kwargs], key) ||
60
+ check(args, key) ||
61
+ check(kwargs, key)
62
+ end
63
+ end
60
64
  end
61
65
  end
@@ -31,9 +31,9 @@ module Bp3
31
31
  private
32
32
 
33
33
  def global_scope
34
- { # TODO: determine why only workspace needs to be provided to make it work
35
- # sites_site_id: global_site_id,
36
- # tenant_id: global_tenant_id,
34
+ {
35
+ sites_site_id: global_site_id,
36
+ tenant_id: global_tenant_id,
37
37
  workspaces_workspace_id: global_workspace_id
38
38
  }
39
39
  end
@@ -67,19 +67,19 @@ module Bp3
67
67
 
68
68
  class ApplicationJob
69
69
  # include Que::ActiveJob::JobExtensions
70
- include CommonIncludes
71
- include JobIncludes
70
+ include Bp3::Noticed::CommonIncludes
71
+ include Bp3::Noticed::JobIncludes
72
72
 
73
73
  # Automatically retry jobs that encountered a deadlock
74
74
  retry_on ActiveRecord::Deadlocked
75
75
  end
76
76
 
77
77
  class EventJob
78
- prepend PrependPerform
78
+ prepend Bp3::Noticed::PrependPerform
79
79
  end
80
80
 
81
81
  class DeliveryMethod
82
- prepend PrependPerform
82
+ prepend Bp3::Noticed::PrependPerform
83
83
  end
84
84
  end
85
85
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bp3
4
4
  module Noticed
5
- VERSION = '0.1.1'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bp3-noticed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wim den Braven
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-04 00:00:00.000000000 Z
11
+ date: 2024-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport