pub_sub_model_sync 1.1.0 → 1.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +10 -10
- data/README.md +17 -14
- data/lib/pub_sub_model_sync/message_publisher.rb +1 -1
- data/lib/pub_sub_model_sync/service_base.rb +1 -1
- data/lib/pub_sub_model_sync/transaction.rb +1 -1
- data/lib/pub_sub_model_sync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84f478587ccd28d92b653744e72d338cf53818e5286544ff2c6e1e982a5a12a7
|
4
|
+
data.tar.gz: 32266d8a3ba69cad2e716c4861914b62e87ee96cf226ecf8f67dab3f909d9856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02a727027a13d0b55f330395c95f9077568efb74fae3927c941211a4d849910fd6c071dae5fdd9386b3bb34c5257389cd74e4fcf5979e29f665a9b8e9e93aa95
|
7
|
+
data.tar.gz: 896f7430fbc83640ef3141a9e24413de69034ebc2d9e6a66987d734e25e9c41e52f03aa23faa494d9f05d0e4628acd058082e729a1de00c513fb0fb1c2cca70e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
# 1.1.1 (October 25, 2021)
|
4
|
+
- feat: include `ordering_key topic_name` when delivering a notification for debugging purposes
|
5
|
+
- doc: improve docs
|
6
|
+
|
3
7
|
# 1.1.0 (October 25, 2021)
|
4
8
|
- feat: change `transactions_max_buffer` default value to 1 to deliver notifications once they were called
|
5
9
|
- feat: use `after_commit` instead of `before_commit` callback and remove the horrible AR patch for rails 4
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pub_sub_model_sync (1.1.
|
4
|
+
pub_sub_model_sync (1.1.1)
|
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.4.2)
|
103
|
+
activesupport (>= 4.2.0)
|
104
104
|
google-cloud-core (1.6.0)
|
105
105
|
google-cloud-env (~> 1.0)
|
106
106
|
google-cloud-errors (~> 1.0)
|
@@ -139,27 +139,27 @@ GEM
|
|
139
139
|
i18n (1.8.10)
|
140
140
|
concurrent-ruby (~> 1.0)
|
141
141
|
jwt (2.2.3)
|
142
|
-
loofah (2.
|
142
|
+
loofah (2.9.1)
|
143
143
|
crass (~> 1.0.2)
|
144
144
|
nokogiri (>= 1.5.9)
|
145
145
|
mail (2.7.1)
|
146
146
|
mini_mime (>= 0.1.1)
|
147
|
-
marcel (1.0.
|
147
|
+
marcel (1.0.1)
|
148
148
|
memoist (0.16.2)
|
149
149
|
method_source (1.0.0)
|
150
150
|
mini_mime (1.0.3)
|
151
151
|
minitest (5.14.4)
|
152
152
|
multi_json (1.15.0)
|
153
153
|
multipart-post (2.1.1)
|
154
|
-
nio4r (2.5.
|
155
|
-
nokogiri (1.
|
154
|
+
nio4r (2.5.7)
|
155
|
+
nokogiri (1.11.3-x86_64-darwin)
|
156
156
|
racc (~> 1.4)
|
157
157
|
os (1.1.1)
|
158
158
|
parallel (1.20.1)
|
159
159
|
parser (3.0.1.1)
|
160
160
|
ast (~> 2.4.1)
|
161
161
|
public_suffix (4.0.6)
|
162
|
-
racc (1.
|
162
|
+
racc (1.5.2)
|
163
163
|
rack (2.2.3)
|
164
164
|
rack-test (1.1.0)
|
165
165
|
rack (>= 1.0, < 3)
|
@@ -181,7 +181,7 @@ GEM
|
|
181
181
|
rails-dom-testing (2.0.3)
|
182
182
|
activesupport (>= 4.2.0)
|
183
183
|
nokogiri (>= 1.6)
|
184
|
-
rails-html-sanitizer (1.
|
184
|
+
rails-html-sanitizer (1.3.0)
|
185
185
|
loofah (~> 2.3)
|
186
186
|
railties (6.1.3.2)
|
187
187
|
actionpack (= 6.1.3.2)
|
@@ -238,7 +238,7 @@ GEM
|
|
238
238
|
tzinfo (2.0.4)
|
239
239
|
concurrent-ruby (~> 1.0)
|
240
240
|
unicode-display_width (1.7.0)
|
241
|
-
websocket-driver (0.7.
|
241
|
+
websocket-driver (0.7.3)
|
242
242
|
websocket-extensions (>= 0.1.0)
|
243
243
|
websocket-extensions (0.1.5)
|
244
244
|
zeitwerk (2.4.2)
|
data/README.md
CHANGED
@@ -311,11 +311,14 @@ Any notification before delivering is transformed as a Payload for a better port
|
|
311
311
|
- `klass`: (String) Notification class name
|
312
312
|
- `mode`: (Symbol: `:model`|`:class`) Kind of notification
|
313
313
|
* `headers`: (Hash) Notification settings that defines how the notification will be processed or delivered.
|
314
|
-
- `
|
315
|
-
- `
|
316
|
-
Note: Final `ordering_key` is calculated
|
317
|
-
- `topic_name`: (String|Array<String>, optional): Specific topic name
|
318
|
-
- `forced_ordering_key`: (String, optional):
|
314
|
+
- `ordering_key`: (String, optional): notifications with the same `ordering_key` are processed in the same order they were delivered, default: `<model.class.name>/<model.id>` when instance notification and `klass_name` when class notification.
|
315
|
+
- `key`: (String, optional) Internal identifier of the payload, default: `<model.class.name>/<action>/<model.id>` when model notification and `<klass_name>/<action>` when class notification (Useful for caching techniques).
|
316
|
+
Note: Final `ordering_key` is calculated as: `payload.headers[:forced_ordering_key] || current_transaction&.key || payload.headers[:ordering_key]`
|
317
|
+
- `topic_name`: (String|Array<String>, optional): Specific topic name where to deliver the notification (default `PubSubModelSync::Config.topic_name`).
|
318
|
+
- `forced_ordering_key`: (String, optional): Overrides `ordering_key` with the provided value even withing transactions. Default `nil`.
|
319
|
+
- `app_key`: (Auto calculated): Name of the application who delivered the notification.
|
320
|
+
- `uuid`: (Auto calculated): Unique notification identifier (Very useful when debugging).
|
321
|
+
Note: To reduce Payload size, some header info are not delivered (Enable debug mode to deliver all payload info).
|
319
322
|
|
320
323
|
- Actions
|
321
324
|
```ruby
|
@@ -528,7 +531,7 @@ config.debug = true
|
|
528
531
|
Topic name(s) to be used to listen all notifications from when listening. Additionally first topic name is used as the default topic name when publishing a notification.
|
529
532
|
- `.subscription_name = "my-app-1"`: (String, default Rails.application.name)
|
530
533
|
Subscriber's identifier which helps to:
|
531
|
-
* skip self
|
534
|
+
* skip self notifications
|
532
535
|
* continue the sync from the last synced notification when service was restarted.
|
533
536
|
- `.default_topic_name = "my_topic"`: (String|Array<String>, optional(default first topic from `topic_name`))
|
534
537
|
Topic name used as the default topic if not defined in the payload when publishing a notification
|
@@ -537,17 +540,17 @@ config.debug = true
|
|
537
540
|
- ```.logger = Rails.logger```
|
538
541
|
(Logger) => define custom logger
|
539
542
|
- ```.on_before_processing = ->(payload, {subscriber:}) { puts payload }```
|
540
|
-
(Proc) => called before processing received
|
543
|
+
(Proc) => called before processing a received notification (:cancel can be returned to skip processing)
|
541
544
|
- ```.on_success_processing = ->(payload, {subscriber:}) { puts payload }```
|
542
|
-
(Proc) => called when a
|
545
|
+
(Proc) => called when a notification was successfully processed
|
543
546
|
- ```.on_error_processing = ->(exception, {payload:, subscriber:}) { payload.delay(...).process! }```
|
544
|
-
(Proc) => called when a
|
547
|
+
(Proc) => called when a notification has failed when processing (delayed_job or similar can be used for retrying)
|
545
548
|
- ```.on_before_publish = ->(payload) { puts payload }```
|
546
|
-
(Proc) => called before publishing a
|
549
|
+
(Proc) => called before publishing a notification (:cancel can be returned to skip publishing)
|
547
550
|
- ```.on_after_publish = ->(payload) { puts payload }```
|
548
|
-
(Proc) => called after publishing a
|
551
|
+
(Proc) => called after publishing a notification
|
549
552
|
- ```.on_error_publish = ->(exception, {payload:}) { payload.delay(...).publish! }```
|
550
|
-
(Proc) => called when failed publishing a
|
553
|
+
(Proc) => called when failed publishing a notification (delayed_job or similar can be used for retrying)
|
551
554
|
- ```.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
555
|
Once this quantity of notifications is reached, then all notifications of the current transaction will immediately be delivered (can be customized per transaction).
|
553
556
|
Note: There is no way to rollback delivered notifications if current transaction fails later.
|
@@ -555,7 +558,7 @@ config.debug = true
|
|
555
558
|
|
556
559
|
## **TODO**
|
557
560
|
- Auto publish update only if payload has changed (see ways to compare previous payload vs new payload)
|
558
|
-
- Improve transactions to exclude similar
|
561
|
+
- Improve transactions to exclude similar notifications by klass and action. Sample:
|
559
562
|
```PubSubModelSync::MessagePublisher.transaction(key, { same_keys: :use_last_as_first|:use_last|:use_first_as_last|:keep*, same_data: :use_last_as_first*|:use_last|:use_first_as_last|:keep })```
|
560
563
|
- Add DB table to use as a shield to prevent publishing similar notifications and publish partial notifications (similar idea when processing notif)
|
561
564
|
- Last notification is not being delivered immediately in google pubsub (maybe force with timeout 10secs and service.deliver_messages)
|
@@ -563,7 +566,7 @@ config.debug = true
|
|
563
566
|
- Services support to deliver multiple payloads from transactions
|
564
567
|
- Fix deprecation warnings: pub_sub_model_sync/service_google.rb:39: warning: Splitting the last argument into positional and keyword parameters is deprecated
|
565
568
|
- Add if/unless to ps_after_action
|
566
|
-
- Add subscription liveness checker using thread without db connection to check periodically pending
|
569
|
+
- Add subscription liveness checker using thread without db connection to check periodically pending notifications from google pubsub
|
567
570
|
- Unify .stop() and 'Listener stopped'
|
568
571
|
|
569
572
|
## **Q&A**
|
@@ -31,7 +31,7 @@ module PubSubModelSync
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# Starts a new transaction
|
34
|
-
# @param key (String
|
34
|
+
# @param key (String, Nil)
|
35
35
|
# @return (Transaction)
|
36
36
|
def init_transaction(key, settings = {})
|
37
37
|
new_transaction = PubSubModelSync::Transaction.new(key, settings)
|
@@ -24,7 +24,7 @@ module PubSubModelSync
|
|
24
24
|
# @return (String): Json Format
|
25
25
|
def encode_payload(payload)
|
26
26
|
data = payload.to_h
|
27
|
-
not_important_keys = %i[
|
27
|
+
not_important_keys = %i[forced_ordering_key]
|
28
28
|
reduce_payload_size = !config.debug
|
29
29
|
data[:headers].except!(*not_important_keys) if reduce_payload_size
|
30
30
|
data.to_json
|
@@ -5,7 +5,7 @@ module PubSubModelSync
|
|
5
5
|
PUBLISHER_KLASS = PubSubModelSync::MessagePublisher
|
6
6
|
attr_accessor :key, :payloads, :max_buffer, :root, :children, :finished
|
7
7
|
|
8
|
-
# @param key (String,
|
8
|
+
# @param key (String,Nil) Transaction key, if empty will use the ordering_key from first payload
|
9
9
|
# @param max_buffer (Integer) Once this quantity of notifications is reached, then all notifications
|
10
10
|
# will immediately be delivered.
|
11
11
|
# Note: There is no way to rollback delivered notifications if current transaction fails
|
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.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|