table_sync 2.3.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +40 -0
- data/Gemfile.lock +82 -77
- data/README.md +4 -2
- data/docs/message_protocol.md +24 -0
- data/docs/notifications.md +45 -0
- data/docs/publishing.md +147 -0
- data/docs/receiving.md +341 -0
- data/lib/table_sync.rb +16 -31
- data/lib/table_sync/errors.rb +39 -23
- data/lib/table_sync/publishing.rb +11 -0
- data/lib/table_sync/{base_publisher.rb → publishing/base_publisher.rb} +1 -1
- data/lib/table_sync/{batch_publisher.rb → publishing/batch_publisher.rb} +4 -4
- data/lib/table_sync/{orm_adapter → publishing/orm_adapter}/active_record.rb +3 -7
- data/lib/table_sync/{orm_adapter → publishing/orm_adapter}/sequel.rb +2 -6
- data/lib/table_sync/{publisher.rb → publishing/publisher.rb} +4 -4
- data/lib/table_sync/receiving.rb +14 -0
- data/lib/table_sync/receiving/config.rb +218 -0
- data/lib/table_sync/receiving/config_decorator.rb +27 -0
- data/lib/table_sync/receiving/dsl.rb +28 -0
- data/lib/table_sync/receiving/handler.rb +131 -0
- data/lib/table_sync/{model → receiving/model}/active_record.rb +36 -22
- data/lib/table_sync/{model → receiving/model}/sequel.rb +13 -8
- data/lib/table_sync/utils.rb +9 -0
- data/lib/table_sync/utils/interface_checker.rb +97 -0
- data/lib/table_sync/utils/proc_array.rb +17 -0
- data/lib/table_sync/utils/proc_keywords_resolver.rb +46 -0
- data/lib/table_sync/version.rb +1 -1
- data/table_sync.gemspec +2 -1
- metadata +42 -30
- data/docs/development.md +0 -43
- data/docs/synopsis.md +0 -336
- data/lib/table_sync/config.rb +0 -105
- data/lib/table_sync/config/callback_registry.rb +0 -53
- data/lib/table_sync/config_decorator.rb +0 -38
- data/lib/table_sync/dsl.rb +0 -25
- data/lib/table_sync/event_actions.rb +0 -96
- data/lib/table_sync/event_actions/data_wrapper.rb +0 -7
- data/lib/table_sync/event_actions/data_wrapper/base.rb +0 -23
- data/lib/table_sync/event_actions/data_wrapper/destroy.rb +0 -19
- data/lib/table_sync/event_actions/data_wrapper/update.rb +0 -21
- data/lib/table_sync/plugins.rb +0 -72
- data/lib/table_sync/plugins/abstract.rb +0 -55
- data/lib/table_sync/plugins/access_mixin.rb +0 -49
- data/lib/table_sync/plugins/registry.rb +0 -153
- data/lib/table_sync/receiving_handler.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63d56abd7c8729d7301e24bf4da9b6e1b8f4a44c387f3041a746398ed1bb381e
|
4
|
+
data.tar.gz: 10344d248c85c9effc5f25ef1442b176a2c90f2135efea3dfaf653df2c53d408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c2dc57d1e62c294ffab4e2ec32361b1bcecdc06f3037f6944fb044e19f3fe6f9efe1409b086ab6b8bbe0f5ac801cc609896a5750733bc4536a0f4c11806a008
|
7
|
+
data.tar.gz: edb939c55898245a92ac762adbbf933cfd4fb7fc6ebf8e4c0bc1a18398ecd2d354f7604f851206c0c1c7a6b1f2eab4af987a0505a204a6cbdff2966e37257800
|
data/.rubocop.yml
CHANGED
@@ -14,3 +14,24 @@ AllCops:
|
|
14
14
|
Style/Alias:
|
15
15
|
Enabled: true
|
16
16
|
EnforcedStyle: prefer_alias_method
|
17
|
+
|
18
|
+
RSpec/ExampleLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Lint/UnusedBlockArgument:
|
22
|
+
AllowUnusedKeywordArguments: true
|
23
|
+
|
24
|
+
Lint/UnusedMethodArgument:
|
25
|
+
AllowUnusedKeywordArguments: true
|
26
|
+
|
27
|
+
Style/AccessorGrouping:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/NumericPredicate:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Lint/MissingSuper:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Style/MissingRespondToMissing:
|
37
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,46 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [4.0.0] - 2020-10-23
|
5
|
+
### Returned
|
6
|
+
- config inheritance
|
7
|
+
|
8
|
+
### Removed
|
9
|
+
- TableSync::Plugins
|
10
|
+
|
11
|
+
## [3.0.0] - 2020-09-05
|
12
|
+
### Added
|
13
|
+
- option `except`
|
14
|
+
- `to_model` in receive method
|
15
|
+
- TableSync::Utils::InterfaceChecker
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
- .rubocop.yml
|
19
|
+
- documentation
|
20
|
+
- modules hierarchy (split receiving and publishing)
|
21
|
+
`TableSync::Publisher` -> `TableSync::Publishing::Publisher`
|
22
|
+
`TableSync::BatchPublisher` -> `TableSync::Publishing::BatchPublisher`
|
23
|
+
`TableSync::ReceivingHandler` -> `TableSync::Receiving::Handler`
|
24
|
+
- made data batches processing as native
|
25
|
+
- implemented callbacks as options
|
26
|
+
- implemented `wrap_receiving` as option
|
27
|
+
- type checking in options
|
28
|
+
- `before_commit on: event, &block` -> `before_update(&block)` or `before_destroy(&block)`
|
29
|
+
- `after_commit on: event, &block` -> `after_commit_on_update(&block)` or `after_commit_on_destroy(&block)`
|
30
|
+
- changed parameters in some options:
|
31
|
+
add `raw_data`
|
32
|
+
`current_row` -> `row`
|
33
|
+
...
|
34
|
+
see documents for details
|
35
|
+
|
36
|
+
### Removed
|
37
|
+
- TableSync::Config::CallbackRegistry
|
38
|
+
- TableSync::EventActions
|
39
|
+
- TableSync::EventActions::DataWrapper
|
40
|
+
- config option `on_destroy`
|
41
|
+
- config option `partitions`
|
42
|
+
- config option `first_sync_time_key`
|
43
|
+
|
4
44
|
## [2.3.0] - 2020-07-22
|
5
45
|
### Added
|
6
46
|
- ruby 2.7 in Travis
|
data/Gemfile.lock
CHANGED
@@ -1,64 +1,65 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
table_sync (
|
4
|
+
table_sync (4.0.0)
|
5
5
|
memery
|
6
6
|
rabbit_messaging (~> 0.3)
|
7
7
|
rails
|
8
|
+
self_data
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
12
|
-
actioncable (6.0.3.
|
13
|
-
actionpack (= 6.0.3.
|
13
|
+
actioncable (6.0.3.4)
|
14
|
+
actionpack (= 6.0.3.4)
|
14
15
|
nio4r (~> 2.0)
|
15
16
|
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailbox (6.0.3.
|
17
|
-
actionpack (= 6.0.3.
|
18
|
-
activejob (= 6.0.3.
|
19
|
-
activerecord (= 6.0.3.
|
20
|
-
activestorage (= 6.0.3.
|
21
|
-
activesupport (= 6.0.3.
|
17
|
+
actionmailbox (6.0.3.4)
|
18
|
+
actionpack (= 6.0.3.4)
|
19
|
+
activejob (= 6.0.3.4)
|
20
|
+
activerecord (= 6.0.3.4)
|
21
|
+
activestorage (= 6.0.3.4)
|
22
|
+
activesupport (= 6.0.3.4)
|
22
23
|
mail (>= 2.7.1)
|
23
|
-
actionmailer (6.0.3.
|
24
|
-
actionpack (= 6.0.3.
|
25
|
-
actionview (= 6.0.3.
|
26
|
-
activejob (= 6.0.3.
|
24
|
+
actionmailer (6.0.3.4)
|
25
|
+
actionpack (= 6.0.3.4)
|
26
|
+
actionview (= 6.0.3.4)
|
27
|
+
activejob (= 6.0.3.4)
|
27
28
|
mail (~> 2.5, >= 2.5.4)
|
28
29
|
rails-dom-testing (~> 2.0)
|
29
|
-
actionpack (6.0.3.
|
30
|
-
actionview (= 6.0.3.
|
31
|
-
activesupport (= 6.0.3.
|
30
|
+
actionpack (6.0.3.4)
|
31
|
+
actionview (= 6.0.3.4)
|
32
|
+
activesupport (= 6.0.3.4)
|
32
33
|
rack (~> 2.0, >= 2.0.8)
|
33
34
|
rack-test (>= 0.6.3)
|
34
35
|
rails-dom-testing (~> 2.0)
|
35
36
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
-
actiontext (6.0.3.
|
37
|
-
actionpack (= 6.0.3.
|
38
|
-
activerecord (= 6.0.3.
|
39
|
-
activestorage (= 6.0.3.
|
40
|
-
activesupport (= 6.0.3.
|
37
|
+
actiontext (6.0.3.4)
|
38
|
+
actionpack (= 6.0.3.4)
|
39
|
+
activerecord (= 6.0.3.4)
|
40
|
+
activestorage (= 6.0.3.4)
|
41
|
+
activesupport (= 6.0.3.4)
|
41
42
|
nokogiri (>= 1.8.5)
|
42
|
-
actionview (6.0.3.
|
43
|
-
activesupport (= 6.0.3.
|
43
|
+
actionview (6.0.3.4)
|
44
|
+
activesupport (= 6.0.3.4)
|
44
45
|
builder (~> 3.1)
|
45
46
|
erubi (~> 1.4)
|
46
47
|
rails-dom-testing (~> 2.0)
|
47
48
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
-
activejob (6.0.3.
|
49
|
-
activesupport (= 6.0.3.
|
49
|
+
activejob (6.0.3.4)
|
50
|
+
activesupport (= 6.0.3.4)
|
50
51
|
globalid (>= 0.3.6)
|
51
|
-
activemodel (6.0.3.
|
52
|
-
activesupport (= 6.0.3.
|
53
|
-
activerecord (6.0.3.
|
54
|
-
activemodel (= 6.0.3.
|
55
|
-
activesupport (= 6.0.3.
|
56
|
-
activestorage (6.0.3.
|
57
|
-
actionpack (= 6.0.3.
|
58
|
-
activejob (= 6.0.3.
|
59
|
-
activerecord (= 6.0.3.
|
52
|
+
activemodel (6.0.3.4)
|
53
|
+
activesupport (= 6.0.3.4)
|
54
|
+
activerecord (6.0.3.4)
|
55
|
+
activemodel (= 6.0.3.4)
|
56
|
+
activesupport (= 6.0.3.4)
|
57
|
+
activestorage (6.0.3.4)
|
58
|
+
actionpack (= 6.0.3.4)
|
59
|
+
activejob (= 6.0.3.4)
|
60
|
+
activerecord (= 6.0.3.4)
|
60
61
|
marcel (~> 0.3.1)
|
61
|
-
activesupport (6.0.3.
|
62
|
+
activesupport (6.0.3.4)
|
62
63
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
63
64
|
i18n (>= 0.7, < 2)
|
64
65
|
minitest (~> 5.1)
|
@@ -70,10 +71,10 @@ GEM
|
|
70
71
|
bundler-audit (0.7.0.1)
|
71
72
|
bundler (>= 1.2.0, < 3)
|
72
73
|
thor (>= 0.18, < 2)
|
73
|
-
bunny (2.
|
74
|
+
bunny (2.17.0)
|
74
75
|
amq-protocol (~> 2.3, >= 2.3.1)
|
75
76
|
coderay (1.1.3)
|
76
|
-
concurrent-ruby (1.1.
|
77
|
+
concurrent-ruby (1.1.7)
|
77
78
|
coveralls (0.8.23)
|
78
79
|
json (>= 1.8, < 3)
|
79
80
|
simplecov (~> 0.16.1)
|
@@ -89,13 +90,12 @@ GEM
|
|
89
90
|
activesupport (>= 4.0, < 7)
|
90
91
|
globalid (0.4.2)
|
91
92
|
activesupport (>= 4.2.0)
|
92
|
-
i18n (1.8.
|
93
|
+
i18n (1.8.5)
|
93
94
|
concurrent-ruby (~> 1.0)
|
94
|
-
jaro_winkler (1.5.4)
|
95
95
|
json (2.3.1)
|
96
96
|
lamian (1.2.0)
|
97
97
|
rails (>= 4.2)
|
98
|
-
loofah (2.
|
98
|
+
loofah (2.7.0)
|
99
99
|
crass (~> 1.0.2)
|
100
100
|
nokogiri (>= 1.5.9)
|
101
101
|
mail (2.7.1)
|
@@ -108,12 +108,12 @@ GEM
|
|
108
108
|
mimemagic (0.3.5)
|
109
109
|
mini_mime (1.0.2)
|
110
110
|
mini_portile2 (2.4.0)
|
111
|
-
minitest (5.14.
|
112
|
-
nio4r (2.5.
|
111
|
+
minitest (5.14.2)
|
112
|
+
nio4r (2.5.4)
|
113
113
|
nokogiri (1.10.10)
|
114
114
|
mini_portile2 (~> 2.4.0)
|
115
115
|
parallel (1.19.2)
|
116
|
-
parser (2.7.1.
|
116
|
+
parser (2.7.1.5)
|
117
117
|
ast (~> 2.4.1)
|
118
118
|
pg (0.21.0)
|
119
119
|
pry (0.13.1)
|
@@ -129,34 +129,35 @@ GEM
|
|
129
129
|
rack (2.2.3)
|
130
130
|
rack-test (1.1.0)
|
131
131
|
rack (>= 1.0, < 3)
|
132
|
-
rails (6.0.3.
|
133
|
-
actioncable (= 6.0.3.
|
134
|
-
actionmailbox (= 6.0.3.
|
135
|
-
actionmailer (= 6.0.3.
|
136
|
-
actionpack (= 6.0.3.
|
137
|
-
actiontext (= 6.0.3.
|
138
|
-
actionview (= 6.0.3.
|
139
|
-
activejob (= 6.0.3.
|
140
|
-
activemodel (= 6.0.3.
|
141
|
-
activerecord (= 6.0.3.
|
142
|
-
activestorage (= 6.0.3.
|
143
|
-
activesupport (= 6.0.3.
|
132
|
+
rails (6.0.3.4)
|
133
|
+
actioncable (= 6.0.3.4)
|
134
|
+
actionmailbox (= 6.0.3.4)
|
135
|
+
actionmailer (= 6.0.3.4)
|
136
|
+
actionpack (= 6.0.3.4)
|
137
|
+
actiontext (= 6.0.3.4)
|
138
|
+
actionview (= 6.0.3.4)
|
139
|
+
activejob (= 6.0.3.4)
|
140
|
+
activemodel (= 6.0.3.4)
|
141
|
+
activerecord (= 6.0.3.4)
|
142
|
+
activestorage (= 6.0.3.4)
|
143
|
+
activesupport (= 6.0.3.4)
|
144
144
|
bundler (>= 1.3.0)
|
145
|
-
railties (= 6.0.3.
|
145
|
+
railties (= 6.0.3.4)
|
146
146
|
sprockets-rails (>= 2.0.0)
|
147
147
|
rails-dom-testing (2.0.3)
|
148
148
|
activesupport (>= 4.2.0)
|
149
149
|
nokogiri (>= 1.6)
|
150
150
|
rails-html-sanitizer (1.3.0)
|
151
151
|
loofah (~> 2.3)
|
152
|
-
railties (6.0.3.
|
153
|
-
actionpack (= 6.0.3.
|
154
|
-
activesupport (= 6.0.3.
|
152
|
+
railties (6.0.3.4)
|
153
|
+
actionpack (= 6.0.3.4)
|
154
|
+
activesupport (= 6.0.3.4)
|
155
155
|
method_source
|
156
156
|
rake (>= 0.8.7)
|
157
157
|
thor (>= 0.20.3, < 2.0)
|
158
158
|
rainbow (3.0.0)
|
159
159
|
rake (13.0.1)
|
160
|
+
regexp_parser (1.8.1)
|
160
161
|
rexml (3.2.4)
|
161
162
|
rspec (3.9.0)
|
162
163
|
rspec-core (~> 3.9.0)
|
@@ -171,30 +172,34 @@ GEM
|
|
171
172
|
diff-lcs (>= 1.2.0, < 2.0)
|
172
173
|
rspec-support (~> 3.9.0)
|
173
174
|
rspec-support (3.9.3)
|
174
|
-
rubocop (0.
|
175
|
-
jaro_winkler (~> 1.5.1)
|
175
|
+
rubocop (0.90.0)
|
176
176
|
parallel (~> 1.10)
|
177
|
-
parser (>= 2.7.
|
177
|
+
parser (>= 2.7.1.1)
|
178
178
|
rainbow (>= 2.2.2, < 4.0)
|
179
|
+
regexp_parser (>= 1.7)
|
179
180
|
rexml
|
181
|
+
rubocop-ast (>= 0.3.0, < 1.0)
|
180
182
|
ruby-progressbar (~> 1.7)
|
181
183
|
unicode-display_width (>= 1.4.0, < 2.0)
|
182
|
-
rubocop-
|
183
|
-
|
184
|
-
|
185
|
-
rubocop
|
186
|
-
rubocop-
|
187
|
-
|
188
|
-
rubocop (
|
189
|
-
rubocop-
|
190
|
-
|
184
|
+
rubocop-ast (0.7.1)
|
185
|
+
parser (>= 2.7.1.5)
|
186
|
+
rubocop-config-umbrellio (0.90.0.93)
|
187
|
+
rubocop (= 0.90.0)
|
188
|
+
rubocop-performance (= 1.7.1)
|
189
|
+
rubocop-rails (= 2.7.0)
|
190
|
+
rubocop-rspec (= 1.42.0)
|
191
|
+
rubocop-performance (1.7.1)
|
192
|
+
rubocop (>= 0.82.0)
|
193
|
+
rubocop-rails (2.7.0)
|
194
|
+
activesupport (>= 4.2.0)
|
191
195
|
rack (>= 1.1)
|
192
|
-
rubocop (>= 0.
|
193
|
-
rubocop-rspec (1.
|
194
|
-
rubocop (>= 0.
|
196
|
+
rubocop (>= 0.87.0)
|
197
|
+
rubocop-rspec (1.42.0)
|
198
|
+
rubocop (>= 0.87.0)
|
195
199
|
ruby-progressbar (1.10.1)
|
196
200
|
ruby2_keywords (0.0.2)
|
197
|
-
|
201
|
+
self_data (1.2.1)
|
202
|
+
sequel (5.37.0)
|
198
203
|
serverengine (2.0.7)
|
199
204
|
sigdump (~> 0.2.2)
|
200
205
|
sigdump (0.2.4)
|
@@ -212,7 +217,7 @@ GEM
|
|
212
217
|
sprockets (4.0.2)
|
213
218
|
concurrent-ruby (~> 1.0)
|
214
219
|
rack (> 1, < 3)
|
215
|
-
sprockets-rails (3.2.
|
220
|
+
sprockets-rails (3.2.2)
|
216
221
|
actionpack (>= 4.0)
|
217
222
|
activesupport (>= 4.0)
|
218
223
|
sprockets (>= 3.0.0)
|
@@ -247,7 +252,7 @@ DEPENDENCIES
|
|
247
252
|
pry
|
248
253
|
rake
|
249
254
|
rspec (~> 3.8)
|
250
|
-
rubocop-config-umbrellio
|
255
|
+
rubocop-config-umbrellio
|
251
256
|
sequel
|
252
257
|
simplecov (~> 0.16)
|
253
258
|
table_sync!
|
data/README.md
CHANGED
@@ -20,8 +20,10 @@ require 'table_sync'
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
- [
|
24
|
-
- [
|
23
|
+
- [Message protocol](docs/message_protocol.md)
|
24
|
+
- [Publising](docs/publishing.md)
|
25
|
+
- [Receiving](docs/receiving.md)
|
26
|
+
- [Notifications](docs/notifications.md)
|
25
27
|
|
26
28
|
## Contributing
|
27
29
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Messages protocol
|
2
|
+
|
3
|
+
```
|
4
|
+
{
|
5
|
+
project_id: "pid",
|
6
|
+
data: {
|
7
|
+
"event": "update",
|
8
|
+
"model": "User",
|
9
|
+
"version": 1.23,
|
10
|
+
"attributes": [
|
11
|
+
{
|
12
|
+
"id": "1",
|
13
|
+
"name": "user1",
|
14
|
+
"email": "user1@example.com"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"id": "2",
|
18
|
+
"name": "user2",
|
19
|
+
"email": "user2@example.com"
|
20
|
+
}
|
21
|
+
]
|
22
|
+
}
|
23
|
+
}
|
24
|
+
```
|
@@ -0,0 +1,45 @@
|
|
1
|
+
### Notifications
|
2
|
+
|
3
|
+
#### ActiveSupport adapter
|
4
|
+
|
5
|
+
You can use an already existing ActiveSupport adapter:
|
6
|
+
```ruby
|
7
|
+
TableSync.notifier = TableSync::InstrumentAdapter::ActiveSupport
|
8
|
+
```
|
9
|
+
|
10
|
+
This instrumentation API is provided by Active Support. It allows to subscribe to notifications:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
ActiveSupport::Notifications.subscribe(/tablesync/) do |name, start, finish, id, payload|
|
14
|
+
# do something
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
Types of events available:
|
19
|
+
`"tablesync.receive.update"`, `"tablesync.receive.destroy"`, `"tablesync.publish.update"`
|
20
|
+
and `"tablesync.publish.destroy"`.
|
21
|
+
|
22
|
+
You have access to the payload, which contains `event`, `direction`, `table`, `schema` and `count`.
|
23
|
+
|
24
|
+
```
|
25
|
+
{
|
26
|
+
:event => :update, # one of update / destroy
|
27
|
+
:direction => :publish, # one of publish / receive
|
28
|
+
:table => "users",
|
29
|
+
:schema => "public",
|
30
|
+
:count => 1
|
31
|
+
}
|
32
|
+
```
|
33
|
+
|
34
|
+
See more at https://guides.rubyonrails.org/active_support_instrumentation.html
|
35
|
+
|
36
|
+
|
37
|
+
#### Custom adapters
|
38
|
+
|
39
|
+
You can also create a custom adapter. It is expected to respond to the following method:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
def notify(table:, event:, direction:, count:)
|
43
|
+
# processes data about table_sync event
|
44
|
+
end
|
45
|
+
```
|
data/docs/publishing.md
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# Publishing changes
|
2
|
+
|
3
|
+
Include `TableSync.sync(self)` into a Sequel or ActiveRecord model. `:if` and `:unless` are
|
4
|
+
supported for Sequel and ActiveRecord
|
5
|
+
|
6
|
+
Functioning `Rails.cache` is required
|
7
|
+
|
8
|
+
Example:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
class SomeModel < Sequel::Model
|
12
|
+
TableSync.sync(self, { if: -> (*) { some_code } })
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
#### #attributes_for_sync
|
17
|
+
|
18
|
+
Models can implement `#attributes_for_sync` to override which attributes are published. If not
|
19
|
+
present, all attributes are published
|
20
|
+
|
21
|
+
#### #attrs_for_routing_key
|
22
|
+
|
23
|
+
Models can implement `#attrs_for_routing_key` to override which attributes are given to routing_key_callable. If not present, default attributes are given
|
24
|
+
|
25
|
+
#### #attrs_for_metadata
|
26
|
+
|
27
|
+
Models can implement `#attrs_for_metadata` to override which attributes are given to metadata_callable. If not present, default attributes are given
|
28
|
+
|
29
|
+
#### .table_sync_model_name
|
30
|
+
|
31
|
+
Models can implement `.table_sync_model_name` class method to override the model name used for
|
32
|
+
publishing events. Default is model class name
|
33
|
+
|
34
|
+
#### .table_sync_destroy_attributes(original_attributes)
|
35
|
+
|
36
|
+
Models can implement `.table_sync_destroy_attributes` class method to override the attributes
|
37
|
+
used for publishing destroy events. Default is object's primary key
|
38
|
+
|
39
|
+
## Configuration
|
40
|
+
|
41
|
+
- `TableSync.publishing_job_class_callable` is a callable which should resolve to a ActiveJob
|
42
|
+
subclass that calls TableSync back to actually publish changes (required)
|
43
|
+
|
44
|
+
Example:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
class TableSync::Job < ActiveJob::Base
|
48
|
+
def perform(*args)
|
49
|
+
TableSync::Publisher.new(*args).publish_now
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
- `TableSync.batch_publishing_job_class_callable` is a callable which should resolve to a ActiveJob
|
55
|
+
subclass that calls TableSync batch publisher back to actually publish changes (required for batch publisher)
|
56
|
+
|
57
|
+
- `TableSync.routing_key_callable` is a callable which resolves which routing key to use when
|
58
|
+
publishing changes. It receives object class and attributes (required)
|
59
|
+
|
60
|
+
Example:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
TableSync.routing_key_callable = -> (klass, attributes) { klass.gsub('::', '_').tableize }
|
64
|
+
```
|
65
|
+
|
66
|
+
- `TableSync.routing_metadata_callable` is a callable that adds RabbitMQ headers which can be
|
67
|
+
used in routing (optional). One possible way of using it is defining a headers exchange and
|
68
|
+
routing rules based on key-value pairs (which correspond to sent headers)
|
69
|
+
|
70
|
+
Example:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
TableSync.routing_metadata_callable = -> (klass, attributes) { attributes.slice("project_id") }
|
74
|
+
```
|
75
|
+
|
76
|
+
- `TableSync.exchange_name` defines the exchange name used for publishing (optional, falls back
|
77
|
+
to default Rabbit gem configuration).
|
78
|
+
|
79
|
+
- `TableSync.notifier` is a module that provides publish and recieve notifications.
|
80
|
+
|
81
|
+
# Manual publishing
|
82
|
+
|
83
|
+
`TableSync::Publisher.new(object_class, original_attributes, confirm: true, state: :updated, debounce_time: 45)`
|
84
|
+
where state is one of `:created / :updated / :destroyed` and `confirm` is Rabbit's confirm delivery flag and optional param `debounce_time` determines debounce time in seconds, 1 minute by default.
|
85
|
+
|
86
|
+
# Manual publishing with batches
|
87
|
+
|
88
|
+
You can use `TableSync::BatchPublisher` to publish changes in batches (array of hashes in `attributes`).
|
89
|
+
|
90
|
+
When using `TableSync::BatchPublisher`,` TableSync.routing_key_callable` is called as follows:
|
91
|
+
`TableSync.routing_key_callable.call(klass, {})`, i.e. empty hash is passed instead of attributes.
|
92
|
+
And `TableSync.routing_metadata_callable` is not called at all: metadata is set to empty hash.
|
93
|
+
|
94
|
+
`TableSync::BatchPublisher.new(object_class, original_attributes_array, **options)`, where `original_attributes_array` is an array with hash of attributes of published objects and `options` is a hash of options.
|
95
|
+
|
96
|
+
`options` consists of:
|
97
|
+
- `confirm`, which is a flag for RabbitMQ, `true` by default
|
98
|
+
- `routing_key`, which is a custom key used (if given) to override one from `TableSync.routing_key_callable`, `nil` by default
|
99
|
+
- `push_original_attributes` (default value is `false`), if this option is set to `true`,
|
100
|
+
original_attributes_array will be pushed to Rabbit instead of fetching records from database and sending their mapped attributes.
|
101
|
+
- `headers`, which is an option for custom headers (can be used for headers exchanges routes), `nil` by default
|
102
|
+
- `event`, which is an option for event specification (`:destroy` or `:update`), `:update` by default
|
103
|
+
|
104
|
+
Example:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
TableSync::BatchPublisher.new(
|
108
|
+
"SomeClass",
|
109
|
+
[{ id: 1 }, { id: 2 }],
|
110
|
+
confirm: false,
|
111
|
+
routing_key: "custom_routing_key",
|
112
|
+
push_original_attributes: true,
|
113
|
+
headers: { key: :value },
|
114
|
+
event: :destroy,
|
115
|
+
)
|
116
|
+
```
|
117
|
+
|
118
|
+
# Manual publishing with batches (Russian)
|
119
|
+
|
120
|
+
С помощью класса `TableSync::BatchPublisher` вы можете опубликовать изменения батчами (массивом в `attributes`).
|
121
|
+
|
122
|
+
При использовании `TableSync::BatchPublisher`, `TableSync.routing_key_callable` вызывается следующим образом:
|
123
|
+
`TableSync.routing_key_callable.call(klass, {})`, то есть вместо аттрибутов передается пустой хэш.
|
124
|
+
А `TableSync.routing_metadata_callable` не вызывается вовсе: в метадате устанавливается пустой хэш.
|
125
|
+
|
126
|
+
`TableSync::BatchPublisher.new(object_class, original_attributes_array, **options)`, где `original_attributes_array` - массив с аттрибутами публикуемых объектов и `options`- это хэш с дополнительными опциями.
|
127
|
+
|
128
|
+
`options` состоит из:
|
129
|
+
- `confirm`, флаг для RabbitMQ, по умолчанию - `true`
|
130
|
+
- `routing_key`, ключ, который (если указан) замещает ключ, получаемый из `TableSync.routing_key_callable`, по умолчанию - `nil`
|
131
|
+
- `push_original_attributes` (значение по умолчанию `false`), если для этой опции задано значение true, в Rabbit будут отправлены original_attributes_array, вместо получения значений записей из базы непосредственно перед отправкой.
|
132
|
+
- `headers`, опция для задания headers (можно использовать для задания маршрутов в headers exchange'ах), `nil` по умолчанию
|
133
|
+
- `event`, опция для указания типа события (`:destroy` или `:update`), `:update` по умолчанию
|
134
|
+
|
135
|
+
Example:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
TableSync::BatchPublisher.new(
|
139
|
+
"SomeClass",
|
140
|
+
[{ id: 1 }, { id: 2 }],
|
141
|
+
confirm: false,
|
142
|
+
routing_key: "custom_routing_key",
|
143
|
+
push_original_attributes: true,
|
144
|
+
headers: { key: :value },
|
145
|
+
event: :destroy,
|
146
|
+
)
|
147
|
+
```
|