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, with_rollbar = false) ⇒ Client
constructor
params fetch_interval resource_names.
- #start ⇒ Object
- #stop_request ⇒ Object
- #stop_requested? ⇒ Boolean
Constructor Details
#initialize(context, with_rollbar = false) ⇒ Client
params
fetch_interval
resource_names
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/flydata/query_based_sync/client.rb', line 17 def initialize(context, =false) @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 if Flydata::RollbarHookSetup.new(get_logger).setup end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
32 33 34 |
# File 'lib/flydata/query_based_sync/client.rb', line 32 def context @context end |
#resource_requester ⇒ Object (readonly)
Returns the value of attribute resource_requester.
33 34 35 |
# File 'lib/flydata/query_based_sync/client.rb', line 33 def resource_requester @resource_requester end |
#response_handler ⇒ Object (readonly)
Returns the value of attribute response_handler.
34 35 36 |
# File 'lib/flydata/query_based_sync/client.rb', line 34 def response_handler @response_handler end |
Instance Method Details
#handle_response(response) ⇒ Object
54 55 56 57 58 |
# File 'lib/flydata/query_based_sync/client.rb', line 54 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
36 37 38 39 40 41 |
# File 'lib/flydata/query_based_sync/client.rb', line 36 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
43 44 45 46 47 48 |
# File 'lib/flydata/query_based_sync/client.rb', line 43 def stop_request @finish = true if @running_thread && @running_thread.alive? @running_thread.run end end |
#stop_requested? ⇒ Boolean
50 51 52 |
# File 'lib/flydata/query_based_sync/client.rb', line 50 def stop_requested? !!@finish end |