pub_sub_model_sync 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +11 -15
- data/README.md +8 -7
- data/lib/pub_sub_model_sync/config.rb +1 -2
- data/lib/pub_sub_model_sync/publisher_concern.rb +1 -10
- data/lib/pub_sub_model_sync/railtie.rb +0 -1
- data/lib/pub_sub_model_sync/version.rb +1 -1
- metadata +2 -3
- data/lib/pub_sub_model_sync/initializers/before_commit.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 815981bccbd5dd0a03a603a2883b18c94bc321b37ed44623df65635ba645ea6f
|
4
|
+
data.tar.gz: b6e1bc85b69ce30df24f27726bb6e9950699799ddb67b313d8d9434284783f28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7f94f4d387baa8143f2fd2686a739bebefe12c247c48e6e85a3c7880efecaf02d5f01eb1770627cb06dbaeb9251f39a0052d715278c57e2c2771ca5fa342f61
|
7
|
+
data.tar.gz: 54a48c91cfc4cea1dd1e40583f9ac737dc324c0007e3bd8acb88599bb0322d1e3535c8d2dfe24d9023ebd51bd4abe9e7687974ee7d17028161757d267ce538b3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
# 1.1.0 (October 25, 2021)
|
4
|
+
- feat: change `transactions_max_buffer` default value to 1 to deliver notifications once they were called
|
5
|
+
- feat: use `after_commit` instead of `before_commit` callback and remove the horrible AR patch for rails 4
|
6
|
+
|
3
7
|
# 1.0.1 (August 20, 2021)
|
4
8
|
- refactor: improve service exit when running in k8s
|
5
9
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pub_sub_model_sync (1.0
|
4
|
+
pub_sub_model_sync (1.1.0)
|
5
5
|
rails
|
6
6
|
|
7
7
|
GEM
|
@@ -99,8 +99,8 @@ GEM
|
|
99
99
|
googleapis-common-protos-types (>= 1.0.6, < 2.0)
|
100
100
|
googleauth (~> 0.15, >= 0.15.1)
|
101
101
|
grpc (~> 1.36)
|
102
|
-
globalid (0.
|
103
|
-
activesupport (>=
|
102
|
+
globalid (0.5.2)
|
103
|
+
activesupport (>= 5.0)
|
104
104
|
google-cloud-core (1.6.0)
|
105
105
|
google-cloud-env (~> 1.0)
|
106
106
|
google-cloud-errors (~> 1.0)
|
@@ -116,7 +116,6 @@ GEM
|
|
116
116
|
google-cloud-errors (~> 1.0)
|
117
117
|
grpc-google-iam-v1 (>= 0.6.10, < 2.0)
|
118
118
|
google-protobuf (3.17.0)
|
119
|
-
google-protobuf (3.17.0-x86_64-linux)
|
120
119
|
googleapis-common-protos (1.3.11)
|
121
120
|
google-protobuf (~> 3.14)
|
122
121
|
googleapis-common-protos-types (>= 1.0.6, < 2.0)
|
@@ -133,9 +132,6 @@ GEM
|
|
133
132
|
grpc (1.37.1)
|
134
133
|
google-protobuf (~> 3.15)
|
135
134
|
googleapis-common-protos-types (~> 1.0)
|
136
|
-
grpc (1.37.1-x86_64-linux)
|
137
|
-
google-protobuf (~> 3.15)
|
138
|
-
googleapis-common-protos-types (~> 1.0)
|
139
135
|
grpc-google-iam-v1 (0.6.11)
|
140
136
|
google-protobuf (~> 3.14)
|
141
137
|
googleapis-common-protos (>= 1.3.11, < 2.0)
|
@@ -143,27 +139,27 @@ GEM
|
|
143
139
|
i18n (1.8.10)
|
144
140
|
concurrent-ruby (~> 1.0)
|
145
141
|
jwt (2.2.3)
|
146
|
-
loofah (2.
|
142
|
+
loofah (2.12.0)
|
147
143
|
crass (~> 1.0.2)
|
148
144
|
nokogiri (>= 1.5.9)
|
149
145
|
mail (2.7.1)
|
150
146
|
mini_mime (>= 0.1.1)
|
151
|
-
marcel (1.0.
|
147
|
+
marcel (1.0.2)
|
152
148
|
memoist (0.16.2)
|
153
149
|
method_source (1.0.0)
|
154
150
|
mini_mime (1.0.3)
|
155
151
|
minitest (5.14.4)
|
156
152
|
multi_json (1.15.0)
|
157
153
|
multipart-post (2.1.1)
|
158
|
-
nio4r (2.5.
|
159
|
-
nokogiri (1.
|
154
|
+
nio4r (2.5.8)
|
155
|
+
nokogiri (1.12.5-x86_64-linux)
|
160
156
|
racc (~> 1.4)
|
161
157
|
os (1.1.1)
|
162
158
|
parallel (1.20.1)
|
163
159
|
parser (3.0.1.1)
|
164
160
|
ast (~> 2.4.1)
|
165
161
|
public_suffix (4.0.6)
|
166
|
-
racc (1.
|
162
|
+
racc (1.6.0)
|
167
163
|
rack (2.2.3)
|
168
164
|
rack-test (1.1.0)
|
169
165
|
rack (>= 1.0, < 3)
|
@@ -185,7 +181,7 @@ GEM
|
|
185
181
|
rails-dom-testing (2.0.3)
|
186
182
|
activesupport (>= 4.2.0)
|
187
183
|
nokogiri (>= 1.6)
|
188
|
-
rails-html-sanitizer (1.
|
184
|
+
rails-html-sanitizer (1.4.2)
|
189
185
|
loofah (~> 2.3)
|
190
186
|
railties (6.1.3.2)
|
191
187
|
actionpack (= 6.1.3.2)
|
@@ -242,7 +238,7 @@ GEM
|
|
242
238
|
tzinfo (2.0.4)
|
243
239
|
concurrent-ruby (~> 1.0)
|
244
240
|
unicode-display_width (1.7.0)
|
245
|
-
websocket-driver (0.7.
|
241
|
+
websocket-driver (0.7.5)
|
246
242
|
websocket-extensions (>= 0.1.0)
|
247
243
|
websocket-extensions (0.1.5)
|
248
244
|
zeitwerk (2.4.2)
|
@@ -264,4 +260,4 @@ DEPENDENCIES
|
|
264
260
|
sqlite3
|
265
261
|
|
266
262
|
BUNDLED WITH
|
267
|
-
2.2.
|
263
|
+
2.2.29
|
data/README.md
CHANGED
@@ -245,7 +245,7 @@ PubSubModelSync::Payload.new({ ids: [my_user.id] }, { klass: 'User', action: :ba
|
|
245
245
|
- `method_name` (Symbol, optional) method to be called to process action callback, sample: `def my_method(action) ... end`
|
246
246
|
- `block` (Proc, optional) Block to be called to process action callback, sample: `{ |action| ... }`
|
247
247
|
|
248
|
-
**Note1**: Due to rails callback ordering, this method uses `
|
248
|
+
**Note1**: Due to rails callback ordering, this method uses `after_commit on: action {...}` callback when creating or updating models to ensure expected notifications order (More details [**here**](#transactions)).
|
249
249
|
**Note2**: Due to rails callback ordering, this method uses `after_destroy` callback when destroying models to ensure the expected notifications order.
|
250
250
|
|
251
251
|
- `ps_publish(action, data: {}, mapping: [], headers: {}, as_klass: nil)` Delivers an instance notification via pubsub
|
@@ -369,9 +369,7 @@ Any notification before delivering is transformed as a Payload for a better port
|
|
369
369
|
- Manual transactions
|
370
370
|
`PubSubModelSync::MessagePublisher::transaction(key, max_buffer: , &block)`
|
371
371
|
- `key` (String|nil) Key used as the ordering key for all inner notifications (When nil, will use `ordering_key` of the first notification)
|
372
|
-
- `max_buffer:` (
|
373
|
-
If true: will save all notifications and deliver all them when transaction has successfully finished. If transaction has failed, then all saved notifications will be discarded (not delivered).
|
374
|
-
If false: will deliver all notifications immediately (no way to rollback notifications if transaction has failed)
|
372
|
+
- `max_buffer:` (Integer, default: `PubSubModelSync::Config.transactions_max_buffer`) Transaction buffer size (more details in #transactions_max_buffer).
|
375
373
|
Sample:
|
376
374
|
```ruby
|
377
375
|
PubSubModelSync::MessagePublisher::transaction('my-custom-key') do
|
@@ -550,9 +548,10 @@ config.debug = true
|
|
550
548
|
(Proc) => called after publishing a message
|
551
549
|
- ```.on_error_publish = ->(exception, {payload:}) { payload.delay(...).publish! }```
|
552
550
|
(Proc) => called when failed publishing a message (delayed_job or similar can be used for retrying)
|
553
|
-
- ```.transactions_max_buffer =
|
554
|
-
|
555
|
-
|
551
|
+
- ```.transactions_max_buffer = 1``` (Integer, default 1) Controls the maximum quantity of notifications to be enqueued to the transaction-buffer before delivering them and thus adds the ability to rollback notifications if the transaction fails.
|
552
|
+
Once this quantity of notifications is reached, then all notifications of the current transaction will immediately be delivered (can be customized per transaction).
|
553
|
+
Note: There is no way to rollback delivered notifications if current transaction fails later.
|
554
|
+
Note2: Only notifications from the buffer can be rollbacked if the current transaction has failed.
|
556
555
|
|
557
556
|
## **TODO**
|
558
557
|
- Auto publish update only if payload has changed (see ways to compare previous payload vs new payload)
|
@@ -564,6 +563,8 @@ config.debug = true
|
|
564
563
|
- Services support to deliver multiple payloads from transactions
|
565
564
|
- Fix deprecation warnings: pub_sub_model_sync/service_google.rb:39: warning: Splitting the last argument into positional and keyword parameters is deprecated
|
566
565
|
- Add if/unless to ps_after_action
|
566
|
+
- Add subscription liveness checker using thread without db connection to check periodically pending messages from google pubsub
|
567
|
+
- Unify .stop() and 'Listener stopped'
|
567
568
|
|
568
569
|
## **Q&A**
|
569
570
|
- I'm getting error "could not obtain a connection from the pool within 5.000 seconds"... what does this mean?
|
@@ -8,8 +8,7 @@ module PubSubModelSync
|
|
8
8
|
# customizable callbacks
|
9
9
|
cattr_accessor(:debug) { false }
|
10
10
|
cattr_accessor :logger # LoggerInst
|
11
|
-
cattr_accessor(:transactions_max_buffer) {
|
12
|
-
cattr_accessor(:enable_rails4_before_commit) { Rails::VERSION::MAJOR == 4 }
|
11
|
+
cattr_accessor(:transactions_max_buffer) { 1 }
|
13
12
|
|
14
13
|
cattr_accessor(:on_before_processing) { ->(_payload, _info) {} } # return :cancel to skip
|
15
14
|
cattr_accessor(:on_success_processing) { ->(_payload, _info) {} }
|
@@ -67,7 +67,7 @@ module PubSubModelSync
|
|
67
67
|
if action == :destroy
|
68
68
|
after_destroy { instance_exec(action, &callback) }
|
69
69
|
else
|
70
|
-
|
70
|
+
send(:after_commit, on: action) { instance_exec(action, &callback) }
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -80,15 +80,6 @@ module PubSubModelSync
|
|
80
80
|
|
81
81
|
private
|
82
82
|
|
83
|
-
def ps_define_commit_action(action, callback)
|
84
|
-
if PubSubModelSync::Config.enable_rails4_before_commit # rails 4 compatibility
|
85
|
-
define_method("ps_before_#{action}_commit") { instance_exec(action, &callback) }
|
86
|
-
else
|
87
|
-
commit_name = respond_to?(:before_commit) ? :before_commit : :after_commit
|
88
|
-
send(commit_name, on: action) { instance_exec(action, &callback) }
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
83
|
# Initialize calls to start and end pub_sub transactions and deliver all them in the same order
|
93
84
|
def ps_init_transaction_callbacks
|
94
85
|
start_transaction = lambda do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pub_sub_model_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -111,7 +111,6 @@ files:
|
|
111
111
|
- lib/pub_sub_model_sync/base.rb
|
112
112
|
- lib/pub_sub_model_sync/config.rb
|
113
113
|
- lib/pub_sub_model_sync/connector.rb
|
114
|
-
- lib/pub_sub_model_sync/initializers/before_commit.rb
|
115
114
|
- lib/pub_sub_model_sync/message_processor.rb
|
116
115
|
- lib/pub_sub_model_sync/message_publisher.rb
|
117
116
|
- lib/pub_sub_model_sync/mock_google_service.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Rails 4 backward compatibility (Add "simple" ps_before_*_commit callbacks)
|
4
|
-
ActiveRecord::ConnectionAdapters::RealTransaction.class_eval do
|
5
|
-
alias_method :commit_without_before_commit, :commit
|
6
|
-
|
7
|
-
def commit
|
8
|
-
call_before_commit_records if PubSubModelSync::Config.enable_rails4_before_commit
|
9
|
-
commit_without_before_commit
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def call_before_commit_records
|
15
|
-
ite = records.uniq
|
16
|
-
ite.each do |record|
|
17
|
-
action = record.previous_changes.include?(:id) ? :create : :update
|
18
|
-
action = :destroy if record.destroyed?
|
19
|
-
callback_name = "ps_before_#{action}_commit".to_sym
|
20
|
-
record.send(callback_name) if record.respond_to?(callback_name)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|