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

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
29
30
31
32
33
# 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)

  @repository = repository
  @api_keys = api_keys
  @edge_url = edge_url
  @interval = interval

  @logger = logger || FeatureHub::Sdk.default_logger

  @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

#repositoryObject (readonly)

Returns the value of attribute repository.



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

def repository
  @repository
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



67
68
69
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 67

def active
  !@task.nil?
end

#closeObject



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

def close
  cancel_task
end

#context_change(new_header) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 50

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



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

def poll
  @cancel = false
  poll_with_interval
end

#update_interval(interval) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/feature_hub/sdk/poll_edge_service.rb', line 41

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