Class: Flydata::QueryBasedSync::Client
- Inherits:
-
Object
- Object
- Flydata::QueryBasedSync::Client
- Includes:
- FlydataCore::Logger
- Defined in:
- lib/flydata/query_based_sync/client.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_FETCH_INTERVAL =
1 minute
60
- DEFAULT_RETRY_INTERVAL =
1 minute
30
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#resource_requester ⇒ Object
readonly
Returns the value of attribute resource_requester.
-
#response_handler ⇒ Object
readonly
Returns the value of attribute response_handler.
Instance Method Summary collapse
- #handle_response(response) ⇒ Object
-
#initialize(context) ⇒ Client
constructor
params fetch_interval resource_names.
- #start ⇒ Object
- #stop_request ⇒ Object
- #stop_requested? ⇒ Boolean
Constructor Details
#initialize(context) ⇒ Client
params
fetch_interval
resource_names
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/flydata/query_based_sync/client.rb', line 16 def initialize(context) @context = context @resource_requester = self.class::RESOURCE_REQUESTER_CLASS.new(context) @response_handler = self.class::RESPONSE_HANDLER_CLASS.new(context) context.params.tap do |c| @fetch_interval = c.nil? ? DEFAULT_FETCH_INTERVAL : c[:fetch_interval] @retry_interval = c.nil? ? DEFAULT_RETRY_INTERVAL : c[:retry_interval] end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
27 28 29 |
# File 'lib/flydata/query_based_sync/client.rb', line 27 def context @context end |
#resource_requester ⇒ Object (readonly)
Returns the value of attribute resource_requester.
28 29 30 |
# File 'lib/flydata/query_based_sync/client.rb', line 28 def resource_requester @resource_requester end |
#response_handler ⇒ Object (readonly)
Returns the value of attribute response_handler.
29 30 31 |
# File 'lib/flydata/query_based_sync/client.rb', line 29 def response_handler @response_handler end |
Instance Method Details
#handle_response(response) ⇒ Object
49 50 51 52 53 |
# File 'lib/flydata/query_based_sync/client.rb', line 49 def handle_response(response) log_debug("Handling response", table_name: response.table_name, count:response.records.count, new_snapshot: response.new_source_pos, base_snapshot: context..current_snapshot) @response_handler.handle(response) end |
#start ⇒ Object
31 32 33 34 35 36 |
# File 'lib/flydata/query_based_sync/client.rb', line 31 def start raise "Already started - thread:#{@running_thread}" if @running_thread raise "Already stop requested" if @stop_requested @running_thread = Thread.current run_loop end |
#stop_request ⇒ Object
38 39 40 41 42 43 |
# File 'lib/flydata/query_based_sync/client.rb', line 38 def stop_request @finish = true if @running_thread && @running_thread.alive? @running_thread.run end end |
#stop_requested? ⇒ Boolean
45 46 47 |
# File 'lib/flydata/query_based_sync/client.rb', line 45 def stop_requested? !!@finish end |