Class: Flydata::SourcePostgresql::QueryBasedSync::ResourceRequester
- Inherits:
-
QueryBasedSync::ResourceRequester
- Object
- QueryBasedSync::ResourceRequester
- Flydata::SourcePostgresql::QueryBasedSync::ResourceRequester
- Defined in:
- lib/flydata/source_postgresql/query_based_sync/resource_requester.rb
Constant Summary collapse
- RESPONSE_CLASS =
Flydata::SourcePostgresql::QueryBasedSync::Response
Instance Attribute Summary
Attributes inherited from QueryBasedSync::ResourceRequester
Instance Method Summary collapse
-
#create_resource_client(context) ⇒ Object
Override.
-
#fetch_responses_once(table_name, latest_src_pos) ⇒ Object
Override.
Methods inherited from QueryBasedSync::ResourceRequester
#each_response, #initialize, #start
Constructor Details
This class inherits a constructor from Flydata::QueryBasedSync::ResourceRequester
Instance Method Details
#create_resource_client(context) ⇒ Object
Override
14 15 16 |
# File 'lib/flydata/source_postgresql/query_based_sync/resource_requester.rb', line 14 def create_resource_client(context) FlydataCore::Postgresql::PGClient.new(context.dbconf) end |
#fetch_responses_once(table_name, latest_src_pos) ⇒ Object
Override
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/flydata/source_postgresql/query_based_sync/resource_requester.rb', line 19 def fetch_responses_once(table_name, latest_src_pos) table_sym = table_name.to_sym = context.[table_sym] table_src_pos = context.table_src_pos_files[table_sym].pos master_src_pos = context.cur_src_pos_file.pos # Set from_sid, to_sid and pk_values to_sid = latest_src_pos.snapshot pk_values = nil # - table.binlog.pos does not exist if table_src_pos.nil? from_sid = master_src_pos.snapshot # - pk_values exists -> continue from the last transaction elsif table_src_pos.pk_values from_sid = table_src_pos.snapshot to_sid = table_src_pos.to_snapshot pk_values = table_src_pos.pk_values else from_sid = table_src_pos.snapshot end if from_sid == to_sid log_debug("Skip fetching records (No changes)") return end log_debug("Start query", from_sid: from_sid, to_sid: to_sid, pk_values: pk_values) # Create and execute query query = generate_query(, from_sid, to_sid, pk_values) result = @resource_client.query(query) # Create response object based on result responses = build_responses(table_name, result, from_sid: from_sid, to_sid: to_sid, pk_values: pk_values) Array(responses) end |