bp3-noticed 0.1.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c1193948dca5bcda90b8e2c1451a75ee2c93e8573175e178214d3c56a1c91f9b
4
+ data.tar.gz: 43df9cace6940523d31d82f2a45c75b3f705bbeb13f6580eca7655b2577c644e
5
+ SHA512:
6
+ metadata.gz: d3c2ce7e7dd976b1a2a19f0a5989db81e8b76b9010a4e9bc54e52fc1d6c54e7d0e180f4c12f65774d4741534f947f84ef4d3d807ded7a77fa0fb40a51761b223
7
+ data.tar.gz: '09e6152cf5f3b49bc89b8c403cdc395b695ce83f301f7d7c84407ba0452f6f0962dfee93362b1de6f5ae3dfe82dbd9b4ae4fe7bf1407d01dece3dab3bd918c9e'
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,51 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+ - rubocop-capybara
5
+ - rubocop-factory_bot
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 3.2.2
9
+ NewCops: enable
10
+
11
+ Gemspec/DevelopmentDependencies:
12
+ EnforcedStyle: gemspec
13
+
14
+ Lint/ConstantDefinitionInBlock:
15
+ Exclude:
16
+ - lib/bp3/**/railtie.rb
17
+
18
+ Lint/Void:
19
+ Exclude:
20
+ - lib/bp3/**/railtie.rb
21
+
22
+ Metrics/AbcSize:
23
+ Max: 26
24
+
25
+ Metrics/BlockLength:
26
+ Max: 66
27
+
28
+ Metrics/CyclomaticComplexity:
29
+ Max: 10
30
+
31
+ Metrics/MethodLength:
32
+ Max: 15
33
+
34
+ Metrics/ModuleLength:
35
+ Max: 150
36
+
37
+ Metrics/PerceivedComplexity:
38
+ Max: 10
39
+
40
+ Naming/FileName:
41
+ Exclude:
42
+ - lib/bp3-*.rb
43
+
44
+ RSpec/ExampleLength:
45
+ Max: 10
46
+
47
+ RSpec/MultipleExpectations:
48
+ Max: 4
49
+
50
+ Style/Documentation:
51
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.2.2
data/.yardopts ADDED
@@ -0,0 +1,8 @@
1
+ --charset utf-8
2
+ --readme README.md
3
+ --markup markdown
4
+ --title "bp3-noticed"
5
+ --private
6
+ -
7
+ CHANGELOG.md
8
+ LICENSE.txt
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.1] - 2024-06-03
4
+
5
+ - Tweaks and documentation
6
+
7
+ ## [0.1.0] - 2024-05-22
8
+
9
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in bp3-noticed.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,261 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bp3-noticed (0.1.1)
5
+ activesupport (>= 7.1.2, < 8)
6
+ bp3-action_dispatch (>= 0.1, < 1)
7
+ bp3-core (>= 0.1, < 1)
8
+ noticed (~> 2.2)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actioncable (7.1.3.3)
14
+ actionpack (= 7.1.3.3)
15
+ activesupport (= 7.1.3.3)
16
+ nio4r (~> 2.0)
17
+ websocket-driver (>= 0.6.1)
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)
25
+ mail (>= 2.7.1)
26
+ net-imap
27
+ net-pop
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)
34
+ mail (~> 2.5, >= 2.5.4)
35
+ net-imap
36
+ net-pop
37
+ net-smtp
38
+ rails-dom-testing (~> 2.2)
39
+ actionpack (7.1.3.3)
40
+ actionview (= 7.1.3.3)
41
+ activesupport (= 7.1.3.3)
42
+ nokogiri (>= 1.8.5)
43
+ racc
44
+ rack (>= 2.2.4)
45
+ rack-session (>= 1.0.1)
46
+ rack-test (>= 0.6.3)
47
+ rails-dom-testing (~> 2.2)
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)
54
+ globalid (>= 0.6.0)
55
+ nokogiri (>= 1.8.5)
56
+ actionview (7.1.3.3)
57
+ activesupport (= 7.1.3.3)
58
+ builder (~> 3.1)
59
+ erubi (~> 1.11)
60
+ rails-dom-testing (~> 2.2)
61
+ rails-html-sanitizer (~> 1.6)
62
+ activejob (7.1.3.3)
63
+ activesupport (= 7.1.3.3)
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)
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)
76
+ marcel (~> 1.0)
77
+ activesupport (7.1.3.3)
78
+ base64
79
+ bigdecimal
80
+ concurrent-ruby (~> 1.0, >= 1.0.2)
81
+ connection_pool (>= 2.2.5)
82
+ drb
83
+ i18n (>= 1.6, < 2)
84
+ minitest (>= 5.1)
85
+ mutex_m
86
+ tzinfo (~> 2.0)
87
+ ast (2.4.2)
88
+ base64 (0.2.0)
89
+ bigdecimal (3.1.8)
90
+ bp3-action_dispatch (0.1.1)
91
+ actionpack (>= 7.1.2, < 8)
92
+ activesupport (>= 7.1.2, < 8)
93
+ i18n (>= 1.8.11, < 2)
94
+ bp3-core (0.1.2)
95
+ actionview (>= 7.1.2, < 8)
96
+ activesupport (>= 7.1.2, < 8)
97
+ builder (3.2.4)
98
+ byebug (11.1.3)
99
+ concurrent-ruby (1.3.1)
100
+ connection_pool (2.4.1)
101
+ crass (1.0.6)
102
+ date (3.3.4)
103
+ diff-lcs (1.5.1)
104
+ drb (2.2.1)
105
+ erubi (1.12.0)
106
+ globalid (1.2.1)
107
+ activesupport (>= 6.1)
108
+ i18n (1.14.5)
109
+ concurrent-ruby (~> 1.0)
110
+ io-console (0.7.2)
111
+ irb (1.13.1)
112
+ rdoc (>= 4.0.0)
113
+ reline (>= 0.4.2)
114
+ json (2.7.2)
115
+ language_server-protocol (3.17.0.3)
116
+ loofah (2.22.0)
117
+ crass (~> 1.0.2)
118
+ nokogiri (>= 1.12.0)
119
+ mail (2.8.1)
120
+ mini_mime (>= 0.1.1)
121
+ net-imap
122
+ net-pop
123
+ net-smtp
124
+ marcel (1.0.4)
125
+ mini_mime (1.1.5)
126
+ minitest (5.23.1)
127
+ mutex_m (0.2.0)
128
+ net-imap (0.4.12)
129
+ date
130
+ net-protocol
131
+ net-pop (0.1.2)
132
+ net-protocol
133
+ net-protocol (0.2.2)
134
+ timeout
135
+ net-smtp (0.5.0)
136
+ net-protocol
137
+ nio4r (2.7.3)
138
+ nokogiri (1.16.5-x86_64-darwin)
139
+ racc (~> 1.4)
140
+ noticed (2.3.2)
141
+ rails (>= 6.1.0)
142
+ parallel (1.24.0)
143
+ parser (3.3.2.0)
144
+ ast (~> 2.4.1)
145
+ racc
146
+ psych (5.1.2)
147
+ stringio
148
+ racc (1.8.0)
149
+ rack (3.0.11)
150
+ rack-session (2.0.0)
151
+ rack (>= 3.0.0)
152
+ rack-test (2.1.0)
153
+ rack (>= 1.3)
154
+ rackup (2.1.0)
155
+ rack (>= 3)
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)
169
+ bundler (>= 1.15.0)
170
+ railties (= 7.1.3.3)
171
+ rails-dom-testing (2.2.0)
172
+ activesupport (>= 5.0.0)
173
+ minitest
174
+ nokogiri (>= 1.6)
175
+ rails-html-sanitizer (1.6.0)
176
+ loofah (~> 2.21)
177
+ nokogiri (~> 1.14)
178
+ railties (7.1.3.3)
179
+ actionpack (= 7.1.3.3)
180
+ activesupport (= 7.1.3.3)
181
+ irb
182
+ rackup (>= 1.0.0)
183
+ rake (>= 12.2)
184
+ thor (~> 1.0, >= 1.2.2)
185
+ zeitwerk (~> 2.6)
186
+ rainbow (3.1.1)
187
+ rake (13.2.1)
188
+ rdoc (6.7.0)
189
+ psych (>= 4.0.0)
190
+ regexp_parser (2.9.2)
191
+ reline (0.5.8)
192
+ io-console (~> 0.5)
193
+ rexml (3.2.8)
194
+ strscan (>= 3.0.9)
195
+ rspec (3.13.0)
196
+ rspec-core (~> 3.13.0)
197
+ rspec-expectations (~> 3.13.0)
198
+ rspec-mocks (~> 3.13.0)
199
+ rspec-core (3.13.0)
200
+ rspec-support (~> 3.13.0)
201
+ rspec-expectations (3.13.0)
202
+ diff-lcs (>= 1.2.0, < 2.0)
203
+ rspec-support (~> 3.13.0)
204
+ rspec-mocks (3.13.1)
205
+ diff-lcs (>= 1.2.0, < 2.0)
206
+ rspec-support (~> 3.13.0)
207
+ rspec-support (3.13.1)
208
+ rubocop (1.64.1)
209
+ json (~> 2.3)
210
+ language_server-protocol (>= 3.17.0)
211
+ parallel (~> 1.10)
212
+ parser (>= 3.3.0.2)
213
+ rainbow (>= 2.2.2, < 4.0)
214
+ regexp_parser (>= 1.8, < 3.0)
215
+ rexml (>= 3.2.5, < 4.0)
216
+ rubocop-ast (>= 1.31.1, < 2.0)
217
+ ruby-progressbar (~> 1.7)
218
+ unicode-display_width (>= 2.4.0, < 3.0)
219
+ rubocop-ast (1.31.3)
220
+ parser (>= 3.3.1.0)
221
+ rubocop-capybara (2.20.0)
222
+ rubocop (~> 1.41)
223
+ rubocop-factory_bot (2.25.1)
224
+ rubocop (~> 1.41)
225
+ rubocop-rake (0.6.0)
226
+ rubocop (~> 1.0)
227
+ rubocop-rspec (2.30.0)
228
+ rubocop (~> 1.40)
229
+ rubocop-capybara (~> 2.17)
230
+ rubocop-factory_bot (~> 2.22)
231
+ rubocop-rspec_rails (~> 2.28)
232
+ rubocop-rspec_rails (2.28.3)
233
+ rubocop (~> 1.40)
234
+ ruby-progressbar (1.13.0)
235
+ stringio (3.1.0)
236
+ strscan (3.1.0)
237
+ thor (1.3.1)
238
+ timeout (0.4.1)
239
+ tzinfo (2.0.6)
240
+ concurrent-ruby (~> 1.0)
241
+ unicode-display_width (2.5.0)
242
+ webrick (1.8.1)
243
+ websocket-driver (0.7.6)
244
+ websocket-extensions (>= 0.1.0)
245
+ websocket-extensions (0.1.5)
246
+ zeitwerk (2.6.15)
247
+
248
+ PLATFORMS
249
+ x86_64-darwin-22
250
+
251
+ DEPENDENCIES
252
+ bp3-noticed!
253
+ byebug
254
+ rake (~> 13.0)
255
+ rspec (~> 3.0)
256
+ rubocop (~> 1.21)
257
+ rubocop-rake (~> 0.6)
258
+ rubocop-rspec (~> 2.25)
259
+
260
+ BUNDLED WITH
261
+ 2.5.11
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Wim den Braven
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Bp3::Noticed
2
+
3
+ bp3-noticed adapts `noticed` for BP3, the persuavis/black_phoebe_3
4
+ multi-site multi-tenant rails application.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'bp3-noticed'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install bp3-noticed
21
+
22
+ ## Usage
23
+
24
+ Do NOT change Noticed.parent_class, as this gem is making the necessary changes.
25
+
26
+ In your app's `ApplicationJob`:
27
+ ```ruby
28
+ include Bp3::Noticed::CommonIncludes
29
+ include Bp3::Noticed::JobIncludes
30
+ ```
31
+ In every custom job class that inherits from `ApplicationJob`:
32
+ ```ruby
33
+ prepend Bp3::Noticed::PrependPerform
34
+ ```
35
+ If there is que job class (outside of ActiveJob), inheriting from `Que::Job`:
36
+ ```ruby
37
+ include Bp3::Noticed::CommonIncludes
38
+ include Bp3::Noticed::QueIncludes
39
+ ```
40
+ In every custom job class that inherits from that que job class`:
41
+ ```ruby
42
+ prepend Bp3::Noticed::PrependPerform
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
48
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
49
+ prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `rake install`. To release a new
52
+ version, update the version number in `version.rb`, and then run `rake release`,
53
+ which will create a git tag for the version, push git commits and the created tag,
54
+ and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Testing
57
+ Run `rake` to run rspec tests and rubocop linting.
58
+
59
+ ## Documentation
60
+ A `.yardopts` file is provided to support yard documentation.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/bp3/noticed/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'bp3-noticed'
7
+ spec.version = Bp3::Noticed::VERSION
8
+ spec.authors = ['Wim den Braven']
9
+ spec.email = ['wimdenbraven@persuavis.com']
10
+
11
+ spec.summary = 'bp3-noticed adapts noticed for BP3 (persuavis/black_phoebe_3).'
12
+ # spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = 'https://www.black-phoebe.com'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.2.0'
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/persuavis/bp3-noticed'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/persuavis/bp3-noticed/blob/main/CHANGELOG.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_dependency 'activesupport', ['>= 7.1.2', '< 8']
35
+ spec.add_dependency 'bp3-action_dispatch', ['>= 0.1', '< 1']
36
+ spec.add_dependency 'bp3-core', ['>= 0.1', '< 1']
37
+ spec.add_dependency 'noticed', '~> 2.2'
38
+
39
+ spec.add_development_dependency 'byebug'
40
+ spec.add_development_dependency 'rake', '~> 13.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ spec.add_development_dependency 'rubocop', '~> 1.21'
43
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6'
44
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.25'
45
+
46
+ # For more information and examples about making a new gem, check out our
47
+ # guide at: https://bundler.io/guides/creating_gem.html
48
+ spec.metadata['rubygems_mfa_required'] = 'true'
49
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CommonIncludes
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ attr_reader :args, :kwargs
8
+ end
9
+
10
+ class_methods do
11
+ def global_request_state_class
12
+ Bp3::Core::Rqid.global_request_state_class
13
+ end
14
+ end
15
+
16
+ def global_request_state_class
17
+ Bp3::Core::Rqid.global_request_state_class
18
+ end
19
+
20
+ def run(...)
21
+ perform(...)
22
+ end
23
+
24
+ private
25
+
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
30
+
31
+ def state
32
+ run_attrs :state
33
+ end
34
+
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?
40
+
41
+ message = "Unable to find site #{id}"
42
+ include_log_error(key: 'prepend_state.ensure_site', message:)
43
+ end
44
+
45
+ site_class.root_site || site_class.first
46
+ end
47
+
48
+ def site_class
49
+ Bp3::ActionDispatch.site_class
50
+ end
51
+
52
+ def check(hash_or_array, key)
53
+ return nil if hash_or_array.blank?
54
+
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
59
+ 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
+
66
+ def job_key
67
+ self.class.name.underscore
68
+ end
69
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JobIncludes
4
+ extend ActiveSupport::Concern
5
+
6
+ class_methods do
7
+ def enqueue(...)
8
+ new.enqueue(...)
9
+ end
10
+
11
+ def run_now(...)
12
+ perform_later(...) # don't use perform_now, as it won't run in the background
13
+ end
14
+
15
+ def run_soon(...)
16
+ set(wait: 1.minute).perform_later(...)
17
+ end
18
+
19
+ def run_later(...)
20
+ set(wait: 1.hour).perform_later(...)
21
+ end
22
+ end
23
+
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
30
+
31
+ private
32
+
33
+ def job_type
34
+ 'job'
35
+ end
36
+
37
+ def include_log_error(key:, message:, details: {})
38
+ return log_error(key:, message:, details:) if respond_to?(:log_error, true)
39
+
40
+ message = "Warning: #{self.class.name}#log_info: unable to log error #{key}/#{message}/#{details}"
41
+ Rails.logger.warn { message }
42
+ nil
43
+ end
44
+
45
+ def run_attrs(key)
46
+ check(arguments, key)
47
+ end
48
+
49
+ def check(hash_or_array, key)
50
+ return nil if hash_or_array.blank?
51
+
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
56
+ 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
+ end
61
+ 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
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrependPerform
4
+ include CommonIncludes
5
+
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
31
+
32
+ private
33
+
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
43
+
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
+
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
56
+
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
+
61
+ message = "Warning: #{self.class.name}#log_info: unable to log info #{key}/#{message}/#{details}"
62
+ Rails.logger.warn { message }
63
+ nil
64
+ end
65
+
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
+
70
+ message = "Warning: #{self.class.name}#log_exception: unable to log exception #{exception}/#{key}/#{details}"
71
+ Rails.logger.warn { message }
72
+ nil
73
+ end
74
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
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
15
+
16
+ def perform_now(...)
17
+ run(...)
18
+ end
19
+
20
+ def run_now(...)
21
+ enqueue(...) # don't use perform_now, as it won't run in the background
22
+ end
23
+
24
+ def run_soon(*, **kwargs)
25
+ kwargs[:job_options] ||= {}
26
+ kwargs[:job_options][:run_at] ||= 1.minute.from_now
27
+ enqueue(*, **kwargs)
28
+ end
29
+
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
36
+
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
47
+
48
+ private
49
+
50
+ def job_type
51
+ 'que'
52
+ end
53
+
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)
60
+ end
61
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require 'rails/railtie'
4
+
5
+ module Bp3
6
+ module Noticed
7
+ if defined?(Rails.env)
8
+ class Railtie < Rails::Railtie
9
+ initializer 'bp3.noticed.railtie.register' do |app|
10
+ app.config.after_initialize do
11
+ ::Noticed::Event # preload
12
+ ::Noticed::Notification # preload
13
+ ::Noticed::ApplicationJob # preload
14
+ ::Noticed::EventJob # preload
15
+ ::Noticed::DeliveryMethod # preload
16
+ module ::Noticed
17
+ class Event
18
+ include Bp3::Core::Rqid
19
+ include Bp3::Core::Sqnr
20
+ include Bp3::Core::Tenantable
21
+
22
+ configure_tenancy
23
+ use_sqnr_for_ordering
24
+ # has_paper_trail
25
+
26
+ def recipient_attributes_for(recipient)
27
+ # TODO: determine why this is needed, since global state and Tenantable should take care of this
28
+ super.merge(global_scope)
29
+ end
30
+
31
+ private
32
+
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,
37
+ workspaces_workspace_id: global_workspace_id
38
+ }
39
+ end
40
+
41
+ def global_site_id
42
+ global_request_state_class.current_site_id
43
+ end
44
+
45
+ def global_tenant_id
46
+ global_request_state_class.current_tenant_id
47
+ end
48
+
49
+ def global_workspace_id
50
+ global_request_state_class.current_workspace_id
51
+ end
52
+
53
+ def global_request_state_class
54
+ Bp3::Core::Rqid.global_request_state_class
55
+ end
56
+ end
57
+
58
+ class Notification
59
+ include Bp3::Core::Rqid
60
+ include Bp3::Core::Sqnr
61
+ include Bp3::Core::Tenantable
62
+
63
+ configure_tenancy
64
+ use_sqnr_for_ordering
65
+ # has_paper_trail
66
+ end
67
+
68
+ class ApplicationJob
69
+ # include Que::ActiveJob::JobExtensions
70
+ include CommonIncludes
71
+ include JobIncludes
72
+
73
+ # Automatically retry jobs that encountered a deadlock
74
+ retry_on ActiveRecord::Deadlocked
75
+ end
76
+
77
+ class EventJob
78
+ prepend PrependPerform
79
+ end
80
+
81
+ class DeliveryMethod
82
+ prepend PrependPerform
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bp3
4
+ module Noticed
5
+ VERSION = '0.1.1'
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require_relative 'noticed/common_includes'
5
+ require_relative 'noticed/job_includes'
6
+ require_relative 'noticed/que_includes'
7
+ require_relative 'noticed/prepend_perform'
8
+ require_relative 'noticed/railtie'
9
+ require_relative 'noticed/version'
10
+
11
+ module Bp3
12
+ module Noticed
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bp3/noticed'
@@ -0,0 +1,6 @@
1
+ module Bp3
2
+ module Noticed
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bp3-noticed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Wim den Braven
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.1.2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '8'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 7.1.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '8'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bp3-action_dispatch
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.1'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '1'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0.1'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '1'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bp3-core
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0.1'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '1'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0.1'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '1'
73
+ - !ruby/object:Gem::Dependency
74
+ name: noticed
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '2.2'
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '2.2'
87
+ - !ruby/object:Gem::Dependency
88
+ name: byebug
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: rake
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '13.0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '13.0'
115
+ - !ruby/object:Gem::Dependency
116
+ name: rspec
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '3.0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '3.0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: rubocop
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '1.21'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '1.21'
143
+ - !ruby/object:Gem::Dependency
144
+ name: rubocop-rake
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.6'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '0.6'
157
+ - !ruby/object:Gem::Dependency
158
+ name: rubocop-rspec
159
+ requirement: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - "~>"
162
+ - !ruby/object:Gem::Version
163
+ version: '2.25'
164
+ type: :development
165
+ prerelease: false
166
+ version_requirements: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - "~>"
169
+ - !ruby/object:Gem::Version
170
+ version: '2.25'
171
+ description:
172
+ email:
173
+ - wimdenbraven@persuavis.com
174
+ executables: []
175
+ extensions: []
176
+ extra_rdoc_files: []
177
+ files:
178
+ - ".rspec"
179
+ - ".rubocop.yml"
180
+ - ".ruby-version"
181
+ - ".yardopts"
182
+ - CHANGELOG.md
183
+ - Gemfile
184
+ - Gemfile.lock
185
+ - LICENSE.txt
186
+ - README.md
187
+ - Rakefile
188
+ - bp3-noticed.gemspec
189
+ - lib/bp3-noticed.rb
190
+ - lib/bp3/noticed.rb
191
+ - lib/bp3/noticed/common_includes.rb
192
+ - lib/bp3/noticed/job_includes.rb
193
+ - lib/bp3/noticed/prepend_perform.rb
194
+ - lib/bp3/noticed/que_includes.rb
195
+ - lib/bp3/noticed/railtie.rb
196
+ - lib/bp3/noticed/version.rb
197
+ - sig/bp3/noticed.rbs
198
+ homepage: https://www.black-phoebe.com
199
+ licenses:
200
+ - MIT
201
+ metadata:
202
+ allowed_push_host: https://rubygems.org
203
+ homepage_uri: https://www.black-phoebe.com
204
+ source_code_uri: https://github.com/persuavis/bp3-noticed
205
+ changelog_uri: https://github.com/persuavis/bp3-noticed/blob/main/CHANGELOG.md
206
+ rubygems_mfa_required: 'true'
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: 3.2.0
216
+ required_rubygems_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ requirements: []
222
+ rubygems_version: 3.5.11
223
+ signing_key:
224
+ specification_version: 4
225
+ summary: bp3-noticed adapts noticed for BP3 (persuavis/black_phoebe_3).
226
+ test_files: []