pub_sub_model_sync 1.5.0 → 1.5.1pre

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: '0839d268607d201c9f77bbbca404f32aa5af02621b7582256eb384b42b9d3985'
4
- data.tar.gz: 0ad3d2cfdce3ce99eb5d0b95a4292496927befaca2a8e2d83b865af411be2988
3
+ metadata.gz: 55d5a541d463ac4b23a26bbcb2ba14f5c4d6336d72bde40d1ea9c1ff5bc4b89f
4
+ data.tar.gz: 496ed96aacf2c6ab74ffb4f997b00cfffc76168f168647f94fec3fa57bc3ae59
5
5
  SHA512:
6
- metadata.gz: c86be499e21572b796060fc07f5d95191971b87366bbebe3b22737d5eb906f25a6e850f4b4b6f2c08f2790541169f36401fb67b95df0c5da365fda1f76e8751f
7
- data.tar.gz: 3e91e306f83eb4ba8dd5c494aadc90b36a702935d7fb716424af80efee6fe6bce9ff895ae6231aa1c32327d7f468ed2148aa69a5f37842c10e0f50e206dad82a
6
+ metadata.gz: 199e1c3841b4038ec67b189b2da974655d7ce87c637297b59c646628e7cba0359f64f11e8b1e0c4d3db65827ffa3a4f81fb52492bb0e5c40e1f9438b894135a6
7
+ data.tar.gz: 951e65c9e9e7d109b5c3fe9c7e79ffb00ebe7110bbdd7d15c93a1a5c83e460a0512292bfe21b87fc8bba5d11dcf79c75af2723cfc0b61cacef8f6f812cab9834
data/README.md CHANGED
@@ -536,6 +536,8 @@ config.debug = true
536
536
  (Proc) => called after publishing a notification
537
537
  - ```.on_error_publish = ->(exception, {payload:}) { payload.delay(...).publish! }```
538
538
  (Proc) => called when failed publishing a notification (delayed_job or similar can be used for retrying)
539
+ - ```.skip_cache = false```
540
+ (true/false*) => Allow to skip payload optimization (cache settings)
539
541
  - ```.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.
540
542
  Once this quantity of notifications is reached, then all notifications of the current transaction will immediately be delivered (can be customized per transaction).
541
543
  Note: There is no way to rollback delivered notifications if current transaction fails later.
@@ -59,13 +59,17 @@ module PubSubModelSync
59
59
  raise(e)
60
60
  end
61
61
 
62
+ # @param error [StandardError]
62
63
  def lost_db_connection?(error)
63
- connection_lost_classes = %w[ActiveRecord::ConnectionTimeoutError PG::UnableToSend]
64
- connection_lost_classes.include?(error.class.name) || error.message.match?(/lost connection/i)
64
+ classes = %w[ActiveRecord::ConnectionTimeoutError PG::UnableToSend ActiveRecord::ConnectionNotEstablished]
65
+ classes.include?(error.class.name) || error.message.match?(/Lost connection to MySQL server/i)
65
66
  end
66
67
 
67
68
  def retry_process?(error, retries) # rubocop:disable Metrics/MethodLength
68
69
  error_payload = [payload, error.message, error.backtrace]
70
+ if error.message.include('Connection refused') || error.message.include('no connection to the server')
71
+ log("Error pubsub: #{[error.class.name, error.message]} (retries: #{retries}) => #{lost_db_connection?(error)}", :error)
72
+ end
69
73
  return false unless lost_db_connection?(error)
70
74
 
71
75
  if retries <= 5
@@ -38,8 +38,10 @@ module PubSubModelSync
38
38
 
39
39
  # Permits to perform manually the callback for a specific action
40
40
  # @param action (Symbol, default: :create) Only :create|:update|:destroy
41
- def ps_perform_publish(action = :create)
42
- items = self.class.ps_cache_publish_callbacks.select { |item| item[:actions].include?(action) }
41
+ def ps_perform_publish(action = :create, parents_actions: false)
42
+ parent_callbacks = parents_actions ? self.class.superclass.ps_cache_publish_callbacks : []
43
+ callbacks = self.class.ps_cache_publish_callbacks
44
+ items = (callbacks + parent_callbacks).select { |item| item[:actions].include?(action) }
43
45
  raise(StandardError, "No callback found for action :#{action}") if items.empty?
44
46
 
45
47
  items.each { |item| instance_exec(action, &item[:callback]) }
@@ -34,7 +34,7 @@ module PubSubModelSync
34
34
  def process_message(payload_info)
35
35
  payload = decode_payload(payload_info)
36
36
  return unless payload
37
- return if same_app_message?(payload)
37
+ return if same_app_message?(payload) || !target_app_message?(payload)
38
38
 
39
39
  payload.process
40
40
  end
@@ -57,5 +57,10 @@ module PubSubModelSync
57
57
  log("Skipping message from same origin: #{[payload]}") if res && config.debug
58
58
  res
59
59
  end
60
+
61
+ def target_app_message?(payload)
62
+ key = payload.headers[:target_app_key]
63
+ key == config.subscription_key || !key
64
+ end
60
65
  end
61
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PubSubModelSync
4
- VERSION = '1.5.0'
4
+ VERSION = '1.5.1pre'
5
5
  end
@@ -11,8 +11,11 @@ Gem::Specification.new do |spec|
11
11
  spec.authors = ['Owen']
12
12
  spec.email = ['owenperedo@gmail.com']
13
13
 
14
- spec.summary = 'Permit to sync models between apps through pub/sub'
15
- spec.description = 'Permit to sync models between apps through pub/sub'
14
+ spec.summary = 'This gem permits to sync automatically models and custom data between multiple Rails
15
+ applications by publishing notifications via pubsub (Google PubSub, RabbitMQ, or Apache Kafka) and automatically
16
+ processed by all connected applications. Out of the scope, this gem includes transactions to keep Data consistency
17
+ by processing notifications in the order they were delivered.'
18
+ spec.description = spec.summary
16
19
  spec.homepage = 'https://github.com/owen2345/pub_sub_model_sync'
17
20
  spec.license = 'MIT'
18
21
 
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.5.0
4
+ version: 1.5.1pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-02 00:00:00.000000000 Z
11
+ date: 2022-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,7 +80,11 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Permit to sync models between apps through pub/sub
83
+ description: This gem permits to sync automatically models and custom data between
84
+ multiple Rails applications by publishing notifications via pubsub (Google PubSub,
85
+ RabbitMQ, or Apache Kafka) and automatically processed by all connected applications.
86
+ Out of the scope, this gem includes transactions to keep Data consistency by processing
87
+ notifications in the order they were delivered.
84
88
  email:
85
89
  - owenperedo@gmail.com
86
90
  executables: []
@@ -152,12 +156,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
156
  version: '2.4'
153
157
  required_rubygems_version: !ruby/object:Gem::Requirement
154
158
  requirements:
155
- - - ">="
159
+ - - ">"
156
160
  - !ruby/object:Gem::Version
157
- version: '0'
161
+ version: 1.3.1
158
162
  requirements: []
159
163
  rubygems_version: 3.0.8
160
164
  signing_key:
161
165
  specification_version: 4
162
- summary: Permit to sync models between apps through pub/sub
166
+ summary: This gem permits to sync automatically models and custom data between multiple
167
+ Rails applications by publishing notifications via pubsub (Google PubSub, RabbitMQ,
168
+ or Apache Kafka) and automatically processed by all connected applications. Out
169
+ of the scope, this gem includes transactions to keep Data consistency by processing
170
+ notifications in the order they were delivered.
163
171
  test_files: []