pub_sub_model_sync 0.5.5 → 0.5.6

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: 1a19e13bd4fa78cde78749ffa47096832c31abbc3fdc10e3938988c2c4a73d44
4
- data.tar.gz: a6abb31c4d900dbb1f7307833e88056ac6d1621bbed46b4136f289602b5aab5c
3
+ metadata.gz: ebc62742739be4d3291fc1551a8f53bf57d815f7b0ce3a9622e4c06a025e4fab
4
+ data.tar.gz: ec84b83f7b2e176a2030415674b6c09859e40bbd9069fa40ff51041d24de0d4e
5
5
  SHA512:
6
- metadata.gz: 128c4edf32925745e271933c0416c44740c1b553c61f04efb75111787404a419b70185a55527db87d28f4c0d03b534d01ef8e01fa46191b539c1766c315de685
7
- data.tar.gz: 4e73d7f16aead95368d4e6830530259e1d664fb0a23b4fc0f5f49e13aead8b5fbc1778aac8c2ea5a0e7c4f996a10f925d3af51c0730bf962ac6d712a11f7bb84
6
+ metadata.gz: b351a1210c3b747de830e4ed67c527625d7941967e71332189000de5b81cb4286f906d8ab943595c7f7ab4cf7c2238c5458b2ea87620a11705877889552dcfcf
7
+ data.tar.gz: 6d282613d88dfa53460bab1425c10553e89837a31790a49bbbd27f451de39f777b56d99424ef81e046eb459ba5d6b97aea92d6b812830579e9a2996e67c5dc6f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pub_sub_model_sync (0.5.5)
4
+ pub_sub_model_sync (0.5.6)
5
5
  rails
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -319,7 +319,28 @@ config.debug = true
319
319
  To fix the problem, edit config/database.yml and increase the quantity of ```pool: 10```
320
320
  - Google pubsub: How to process notifications parallely and not sequentially (default 1 thread)?
321
321
  ```ruby PubSubModelSync::ServiceGoogle::LISTEN_SETTINGS = { threads: { callback: qty_threads } } ```
322
- Note: by this way some notifications can be processed before others thus missing relationship errors can appear
322
+ Note: by this way some notifications can be processed before others thus missing relationship errors can appear
323
+ - How to retry failed syncs with sidekiq?
324
+ ```ruby
325
+ # lib/initializers/pub_sub_config.rb
326
+
327
+ class PubSubRecovery
328
+ include Sidekiq::Worker
329
+ sidekiq_options queue: :pubsub, retry: 2, backtrace: true
330
+
331
+ def perform(payload_data, action)
332
+ payload = PubSubModelSync::Payload.from_payload_data(payload_data)
333
+ payload.send(action)
334
+ end
335
+ end
336
+
337
+ PubSubModelSync::Config.on_error_publish = lambda do |_e, data|
338
+ PubSubRecovery.perform_async(data[:payload].to_h, :publish!)
339
+ end
340
+ PubSubModelSync::Config.on_error_processing = lambda do |_e, data|
341
+ PubSubRecovery.perform_async(data[:payload].to_h, :process!)
342
+ end
343
+ ```
323
344
 
324
345
  ## Contributing
325
346
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  module PubSubModelSync
4
4
  class Payload
5
+ class MissingInfo < StandardError; end
5
6
  attr_reader :data, :attributes, :headers
6
7
 
7
8
  # @param data (Hash: { any value }):
@@ -11,8 +12,10 @@ module PubSubModelSync
11
12
  @attributes = attributes
12
13
  @headers = headers
13
14
  build_headers
15
+ validate!
14
16
  end
15
17
 
18
+ # @return Hash: payload data
16
19
  def to_h
17
20
  { data: data, attributes: attributes, headers: headers }
18
21
  end
@@ -25,33 +28,52 @@ module PubSubModelSync
25
28
  attributes[:action]
26
29
  end
27
30
 
31
+ # Process payload data
32
+ # (If error will raise exception and wont call on_error_processing callback)
28
33
  def process!
29
34
  process do |publisher|
30
35
  publisher.raise_error = true
31
36
  end
32
37
  end
33
38
 
39
+ # Process payload data
40
+ # (If error will call on_error_processing callback)
34
41
  def process
35
42
  publisher = PubSubModelSync::MessageProcessor.new(self)
36
43
  yield(publisher) if block_given?
37
44
  publisher.process
38
45
  end
39
46
 
47
+ # Publish payload to pubsub
48
+ # (If error will raise exception and wont call on_error_publish callback)
40
49
  def publish!
41
50
  klass = PubSubModelSync::MessagePublisher
42
51
  klass.publish(self, raise_error: true)
43
52
  end
44
53
 
54
+ # Publish payload to pubsub
55
+ # (If error will call on_error_publish callback)
45
56
  def publish
46
57
  klass = PubSubModelSync::MessagePublisher
47
58
  klass.publish(self)
48
59
  end
49
60
 
61
+ # convert payload data into Payload
62
+ # @param data [Hash]: payload data (:data, :attributes, :headers)
63
+ def self.from_payload_data(data)
64
+ data = data.deep_symbolize_keys
65
+ new(data[:data], data[:attributes], data[:headers])
66
+ end
67
+
50
68
  private
51
69
 
52
70
  def build_headers
53
71
  headers[:uuid] ||= SecureRandom.uuid
54
72
  headers[:app_key] ||= PubSubModelSync::Config.subscription_key
55
73
  end
74
+
75
+ def validate!
76
+ raise MissingInfo if !attributes[:klass] || !attributes[:action]
77
+ end
56
78
  end
57
79
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PubSubModelSync
4
- VERSION = '0.5.5'
4
+ VERSION = '0.5.6'
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: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-11 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails