Class: Flydata::QueryBasedSync::Client

Inherits:
Object
  • Object
show all
Includes:
FlydataCore::Logger
Defined in:
lib/flydata/query_based_sync/client.rb

Constant Summary collapse

DEFAULT_FETCH_INTERVAL =

1 minute

60
DEFAULT_RETRY_INTERVAL =

1 minute

30

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contextObject (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_requesterObject (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_handlerObject (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.table_meta.current_snapshot)
  @response_handler.handle(response)
end

#startObject



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_requestObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/flydata/query_based_sync/client.rb', line 45

def stop_requested?
  !!@finish
end