Class: FeatureHub::Sdk::PollingEdgeService

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

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.



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

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.



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

def api_keys
  @api_keys
end

#cancelObject (readonly)

Returns the value of attribute cancel.



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

def cancel
  @cancel
end

#edge_urlObject (readonly)

Returns the value of attribute edge_url.



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

def edge_url
  @edge_url
end

#etagObject (readonly)

Returns the value of attribute etag.



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

def etag
  @etag
end

#intervalObject (readonly)

Returns the value of attribute interval.



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

def interval
  @interval
end

#sha_contextObject (readonly)

Returns the value of attribute sha_context.



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

def sha_context
  @sha_context
end

#stoppedObject (readonly)

Returns the value of attribute stopped.



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

def stopped
  @stopped
end

Instance Method Details

#activeObject



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

def active
  !@task.nil?
end

#closeObject



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

def close
  cancel_task
end

#context_change(new_header) ⇒ Object



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

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



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

def poll
  @cancel = false
  poll_with_interval
end

#update_interval(interval) ⇒ Object



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

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