Class: Hoss::CentralConfig Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/hoss/central_config.rb,
lib/hoss/central_config/cache_control.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: CacheControl, ClientError, ResponseError, ServerError

Constant Summary

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(config) ⇒ CentralConfig

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CentralConfig.



38
39
40
41
42
43
44
# File 'lib/hoss/central_config.rb', line 38

def initialize(config)
  @config = config
  @modified_options = {}
  @authorization = "Bearer #{@config.api_key}"
  @http = Transport::Connection::Http.new(config)
  @etag = 1
end

Instance Attribute Details

#configObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/hoss/central_config.rb', line 46

def config
  @config
end

#promiseObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

for specs



47
48
49
# File 'lib/hoss/central_config.rb', line 47

def promise
  @promise
end

#scheduled_taskObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

for specs



47
48
49
# File 'lib/hoss/central_config.rb', line 47

def scheduled_task
  @scheduled_task
end

Instance Method Details

#assign(update) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/hoss/central_config.rb', line 87

def assign(update)
  # For each updated option, store the original value,
  # unless already stored
  update.each_key do |key|
    @modified_options[key] ||= config.get(key.to_sym)&.value
  end

  # If the new update doesn't set a previously modified option,
  # revert it to the original
  @modified_options.each_key do |key|
    next if update.key?(key)
    update[key] = @modified_options.delete(key)
  end
  @config.replace_options(update)
end

#fetch_and_apply_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
66
67
68
69
# File 'lib/hoss/central_config.rb', line 63

def fetch_and_apply_config
  @promise =
    Concurrent::Promise
    .execute(&method(:fetch_config))
    .on_success(&method(:handle_success))
    .rescue(&method(:handle_error))
end

#fetch_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/hoss/central_config.rb', line 71

def fetch_config
  resp = perform_request
  case resp.status
  when 200..299
    resp
  when 300..399
    resp
  when 400..499
    resp
    # raise ClientError, resp
  when 500..599
    resp
    # raise ServerError, resp
  end
end

#handle_forking!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



103
104
105
106
# File 'lib/hoss/central_config.rb', line 103

def handle_forking!
  stop
  start
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
52
53
54
55
# File 'lib/hoss/central_config.rb', line 49

def start
  return unless config.central_config?

  debug 'Starting CentralConfig'

  fetch_and_apply_config
end

#stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
# File 'lib/hoss/central_config.rb', line 57

def stop
  debug 'Stopping CentralConfig'

  @scheduled_task&.cancel
end