Class: Flydata::QueryBasedSync::ResponseHandler

Inherits:
Object
  • Object
show all
Includes:
PluginSupport::SyncRecordEmittable
Defined in:
lib/flydata/query_based_sync/response_handler.rb

Constant Summary

Constants included from PluginSupport::SyncRecordEmittable

PluginSupport::SyncRecordEmittable::RESPECT_ORDER, PluginSupport::SyncRecordEmittable::SEQ, PluginSupport::SyncRecordEmittable::SRC_POS, PluginSupport::SyncRecordEmittable::TABLE_NAME, PluginSupport::SyncRecordEmittable::TABLE_REV, PluginSupport::SyncRecordEmittable::TYPE, PluginSupport::SyncRecordEmittable::V

Instance Attribute Summary

Attributes included from PluginSupport::SyncRecordEmittable

#context

Instance Method Summary collapse

Methods included from PluginSupport::SyncRecordEmittable

#emit_sync_records

Constructor Details

#initialize(context) ⇒ ResponseHandler

Returns a new instance of ResponseHandler.


9
10
11
# File 'lib/flydata/query_based_sync/response_handler.rb', line 9

def initialize(context)
  @context = context
end

Instance Method Details

#handle(response) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/flydata/query_based_sync/response_handler.rb', line 13

def handle(response)
  records = response.records.collect{|r| {row: r} }

  emit_sync_records(records,
                    type: :update,  # upsert only
                    src_pos: response.new_source_pos.to_s,
                    table: response.table_name)

  # TODO: Revisit and check if transaction management is needed
  # However, since we use 'upsert' for query based sync,
  # duplicate event will not cause an issue.
  context.table_src_pos_files[response.table_name.to_sym].
    save(response.new_source_pos)
end