Class: FeatureHub::Sdk::PollingEdgeService

Inherits:
EdgeService
  • Object
show all
Defined in:
lib/feature_hub/sdk/poll_edge_service.rb

Overview

uses a periodic polling mechanism to get updates

Instance Attribute Summary collapse

Attributes inherited from EdgeService

#repository

Instance Method Summary collapse

Constructor Details

#initialize(repository, api_keys, edge_url, interval, logger = nil) ⇒ PollingEdgeService

Returns a new instance of PollingEdgeService.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 15

def initialize(repository, api_keys, edge_url, interval, logger = nil)
  super(repository, api_keys, edge_url, logger)

  @interval = interval

  @task = nil
  @cancel = false
  @context = nil
  @etag = nil
  @stopped = false
  @sha_context = nil

  generate_url
end

Instance Attribute Details

#api_keysObject (readonly)

Returns the value of attribute api_keys.



13
14
15
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 13

def api_keys
  @api_keys
end

#cancelObject (readonly)

Returns the value of attribute cancel.



13
14
15
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 13

def cancel
  @cancel
end

#edge_urlObject (readonly)

Returns the value of attribute edge_url.



13
14
15
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 13

def edge_url
  @edge_url
end

#etagObject (readonly)

Returns the value of attribute etag.



13
14
15
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 13

def etag
  @etag
end

#intervalObject (readonly)

Returns the value of attribute interval.



13
14
15
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 13

def interval
  @interval
end

#sha_contextObject (readonly)

Returns the value of attribute sha_context.



13
14
15
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 13

def sha_context
  @sha_context
end

#stoppedObject (readonly)

Returns the value of attribute stopped.



13
14
15
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 13

def stopped
  @stopped
end

Instance Method Details

#activeObject



62
63
64
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 62

def active
  !@task.nil?
end

#closeObject



58
59
60
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 58

def close
  cancel_task
end

#context_change(new_header) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 45

def context_change(new_header)
  return if new_header == @context

  @context = new_header
  @sha_context = Digest::SHA256.hexdigest(@context)

  if active
    get_updates
  else
    poll
  end
end

#pollObject

abstract



31
32
33
34
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 31

def poll
  @cancel = false
  poll_with_interval
end

#update_interval(interval) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 36

def update_interval(interval)
  @interval = interval
  if @task.nil?
    poll
  else
    @task.execution_interval = interval
  end
end