pub_sub_model_sync 0.5.8.1 → 0.6.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.
@@ -4,31 +4,29 @@ module PubSubModelSync
4
4
  module SubscriberConcern
5
5
  def self.included(base)
6
6
  base.extend(ClassMethods)
7
- end
8
-
9
- # check if model was changed to skip nonsense .update!()
10
- def ps_subscriber_changed?(_data)
11
- validate
12
- changed?
7
+ base.send(:attr_accessor, :ps_processed_payload)
13
8
  end
14
9
 
15
10
  # permit to apply custom actions before applying sync
16
11
  # @return (nil|:cancel): nil to continue sync OR :cancel to skip sync
17
- def ps_before_save_sync(_payload); end
12
+ def ps_before_save_sync(_action, _payload); end
18
13
 
19
14
  module ClassMethods
20
15
  def ps_subscribe(attrs, actions: nil, from_klass: name, id: :id)
21
- settings = { id: id, from_klass: from_klass }
16
+ settings = { id: id, from_klass: from_klass, mode: :model }
22
17
  actions ||= %i[create update destroy]
23
18
  actions.each do |action|
24
19
  add_ps_subscriber(action, attrs, settings)
25
20
  end
26
21
  end
27
22
 
23
+ def ps_subscribe_custom(action, from_klass: name, id: :id, from_action: nil)
24
+ settings = { id: id, mode: :custom_model, from_klass: from_klass, from_action: from_action }
25
+ add_ps_subscriber(action, nil, settings)
26
+ end
27
+
28
28
  def ps_class_subscribe(action, from_action: nil, from_klass: nil)
29
- settings = { direct_mode: true }
30
- settings[:from_action] = from_action if from_action
31
- settings[:from_klass] = from_klass if from_klass
29
+ settings = { mode: :klass, from_action: from_action, from_klass: from_klass }
32
30
  add_ps_subscriber(action, nil, settings)
33
31
  end
34
32
 
@@ -3,6 +3,17 @@
3
3
  namespace :pub_sub_model_sync do
4
4
  desc 'Start listening syncs'
5
5
  task start: :environment do
6
+ # https://github.com/zendesk/ruby-kafka#consumer-groups
7
+ # Each consumer process will be assigned one or more partitions from each topic that the group
8
+ # subscribes to. In order to handle more messages, simply start more processes.
9
+ if PubSubModelSync::Config.service_name == :kafka
10
+ (PubSubModelSync::ServiceKafka::QTY_WORKERS - 1).times.each do
11
+ Thread.new do
12
+ Thread.current.abort_on_exception = true
13
+ PubSubModelSync::Runner.new.run
14
+ end
15
+ end
16
+ end
6
17
  PubSubModelSync::Runner.new.run
7
18
  end
8
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PubSubModelSync
4
- VERSION = '0.5.8.1'
4
+ VERSION = '0.6.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: 0.5.8.1
4
+ version: 0.6.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-02-05 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -93,6 +93,7 @@ files:
93
93
  - ".rubocop.yml"
94
94
  - CHANGELOG.md
95
95
  - CODE_OF_CONDUCT.md
96
+ - Dockerfile
96
97
  - Gemfile
97
98
  - Gemfile.lock
98
99
  - LICENSE.txt
@@ -100,6 +101,8 @@ files:
100
101
  - Rakefile
101
102
  - bin/console
102
103
  - bin/setup
104
+ - docker-compose.yaml
105
+ - docs/notifications-diagram.png
103
106
  - gemfiles/Gemfile_4
104
107
  - gemfiles/Gemfile_5
105
108
  - gemfiles/Gemfile_6