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, 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, with_rollbar=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 with_rollbar
    Flydata::RollbarHookSetup.new(get_logger).setup
  end
end

Instance Attribute Details

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

#startObject


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_requestObject


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

Returns:

  • (Boolean)

50
51
52
# File 'lib/flydata/query_based_sync/client.rb', line 50

def stop_requested?
  !!@finish
end