pub_sub_model_sync 1.0.1 → 1.1.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: 6e73c2af5a62d4b0ae32ea40f3c3c369a049edfd47360a50386eeb5e4ff97cd1
4
- data.tar.gz: 5d1892ee41ada21c9bf70bcc3601e435edfdf55d7b51b443369bf3307da60436
3
+ metadata.gz: 815981bccbd5dd0a03a603a2883b18c94bc321b37ed44623df65635ba645ea6f
4
+ data.tar.gz: b6e1bc85b69ce30df24f27726bb6e9950699799ddb67b313d8d9434284783f28
5
5
  SHA512:
6
- metadata.gz: 962defddfdc780ce185d01e9069485207bdf66be9b3554a1003b5ec71211c467223c288fbb6c6a59ae819a9ba37ff118a470942bdef9e69c68e94f34ff899c9a
7
- data.tar.gz: c6e771a40a96dcdf00161aa49fbe7c1b5f283709d5b42b87421c6655e4cb9972e9f7d3bb7d203d47c9757dc681f8c755c7026447f6582ffa1f43a553ba90197a
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.1)
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.4.2)
103
- activesupport (>= 4.2.0)
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.9.1)
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.1)
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.7)
159
- nokogiri (1.11.3-x86_64-darwin)
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.5.2)
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.3.0)
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.3)
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.17
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 `before_commit` callback when creating or updating models to ensure expected notifications order (More details [**here**](#transactions)).
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:` (Boolean, default: `PubSubModelSync::Config.transactions_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 = 100``` (Integer) Once this quantity of notifications is reached, then all notifications will immediately be delivered.
554
- Note: There is no way to rollback delivered notifications if current transaction fails
555
- - ```.enable_rails4_before_commit = true``` (true*|false) When false will disable rails 4 hack compatibility and then CRUD notifications will be prepared using `after_commit` callback instead of `before_commit` (used in `ps_after_action(...)`) which will not rollback sql transactions if failed when publishing pubsub notification.
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) { 100 }
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
- ps_define_commit_action(action, callback)
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
@@ -13,7 +13,6 @@ module PubSubModelSync
13
13
  end
14
14
 
15
15
  configure do
16
- require 'pub_sub_model_sync/initializers/before_commit' if PubSubModelSync::Config.enable_rails4_before_commit
17
16
  end
18
17
  end
19
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PubSubModelSync
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.0'
5
5
  end
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.1
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-08-20 00:00:00.000000000 Z
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