-
Notifications
You must be signed in to change notification settings - Fork 12
Common: Notifications
By default, notifications are disabled and notifier isn't set. You must set the notifier during application initialization:
TableSync.notifier = TableSync::InstrumentAdapter::ActiveSupport
When you set the notifier, the notifications are automatically turned on:
TableSync.notifier = TableSync::InstrumentAdapter::ActiveSupport
p TableSync.notify # => "true"
Also, you can disable notifications: TableSync.notify = false
.
You can use an already existing ActiveSupport adapter:
TableSync.notifier = TableSync::InstrumentAdapter::ActiveSupport
This instrumentation API is provided by Active Support. It allows to subscribe to notifications:
ActiveSupport::Notifications.subscribe(/tablesync/) do |name, start, finish, id, payload|
# do something
end
Types of events available:
"tablesync.receive.update"
, "tablesync.receive.destroy"
, "tablesync.publish.update"
and "tablesync.publish.destroy"
.
You have access to the payload, which contains event
, direction
, table
, schema
and count
.
{
:event => :update, # one of update / destroy
:direction => :publish, # one of publish / receive
:table => "users",
:schema => "public",
:count => 1
}
See more at https://guides.rubyonrails.org/active_support_instrumentation.html
You can also create a custom adapter. It is expected to respond to the following method:
def notify(table:, event:, direction:, count:)
# processes data about table_sync event
end