docs/synopsis.md in table_sync-1.12.1 vs docs/synopsis.md in table_sync-1.13.0
- old
+ new
@@ -82,11 +82,11 @@
- `TableSync.notifier` is a module that provides publish and recieve notifications.
# Manual publishing
-`TableSync::Publisher.new(object_class, original_attributes, confirm: true, state: :updated, debounce_time: 45)`
+`TableSync::Publisher.new(object_class, original_attributes, confirm: true, state: :updated, debounce_time: 45)`
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.
# Manual publishing with batches
You can use `TableSync::BatchPublisher` to publish changes in batches (array of hashes in `attributes`).
@@ -222,22 +222,38 @@
- `first_sync_time_key` - name of the column where the time of first record synchronization should be stored. Disabled by default.
- `mapping_overrides` - map for overriding receiving columns
- `additional_data` - additional data for insert or update (e.g. `project_id`)
- `default_values` - values for insert if a row is not found
- `partitions` - proc that is used to obtain partitioned data to support table partitioning. Must return a hash which
- keys are names of partitions of partitioned table and values - arrays of attributes to be inserted into particular
- partition `{ measurements_2018_01: [ { attrs }, ... ], measurements_2018_02: [ { attrs }, ... ], ...}`.
- While the proc is called inside an upsert transaction it is suitable place for creating partitions for new data.
- Note that transaction of proc is a TableSynk.orm transaction.
+ keys are names of partitions of partitioned table and values - arrays of attributes to be inserted into particular
+ partition `{ measurements_2018_01: [ { attrs }, ... ], measurements_2018_02: [ { attrs }, ... ], ...}`.
+ While the proc is called inside an upsert transaction it is suitable place for creating partitions for new data.
+ Note that transaction of proc is a TableSynk.orm transaction.
+ ```ruby
+ partitions do |data:|
+ data.group_by { |d| "measurements_#{d[:time].year}_#{d[:time].month}" }
+ .tap { |data| data.keys.each { |table| DB.run("CREATE TABLE IF NOT EXISTS #{table} PARTITION OF measurements") } }
+ end
+ ```
+- `wrap_reciving` - proc that is used to wrap the receiving logic by custom block of code. Receives `data` and `receiving` attributes
+ (received event data and receiving logic proc respectively). `receiving.call` runs receiving process (you should use it manually).
+ - example (concurrent receiving):
+ ```ruby
+ wrap_receiving do |data, receiving|
+ Locking.acquire("some-lock-key") { receiving.call }
+ end
+ ```
+ - `data` attribute:
+ - for `destroy` event - an instance of `TableSync::EventActions::DataWrapper::Destroy`;
+ - for `update` event - an instance of `TableSync::EventActions::DataWrapper::Update`;
+ - `#event_data` - raw recevied event data:
+ - for `destroy` event - simple `Hash`;
+ - for `update` event - `Hash` with `Hash<ModelKlass, Array<Hash<Symbol, Object>>>` signature;
+ - `#destroy?` / `#update?` - corresponding predicates;
+ - `#type` - indicates a type of data (`:destroy` and `:update` respectively);
+ - `#each` - iterates over `#event_data` elements (acts like an iteration over an array of elements);
-```ruby
-partitions do |data:|
- data.group_by { |d| "measurements_#{d[:time].year}_#{d[:time].month}" }
- .tap { |data| data.keys.each { |table| DB.run("CREATE TABLE IF NOT EXISTS #{table} PARTITION OF measurements") } }
-end
-```
-
Each of options can receive static value or code block which will be called for each event with the following arguments:
- `event` - type of event (`:update` or `:destroy`)
- `model` - source model (`Project`, `News`, `User` in example)
- `version` - version of the data
- `project_id` - id of project which is used in RabbitMQ
@@ -281,10 +297,10 @@
```
{
:event => :update, # one of update / destroy
:direction => :publish, # one of publish / receive
:table => "users",
- :schema => "public",
+ :schema => "public",
:count => 1
}
```
See more at https://guides.rubyonrails.org/active_support_instrumentation.html