Class: EcsDeploy::AutoScaler::TriggerConfig

Inherits:
Struct
  • Object
show all
Extended by:
ConfigBase::ClassMethods
Includes:
ConfigBase
Defined in:
lib/ecs_deploy/auto_scaler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConfigBase::ClassMethods

client_table

Methods included from ConfigBase

#initialize

Instance Attribute Details

#alarm_name ⇒ Object

Returns the value of attribute alarm_name

Returns:

  • (Object) —

    the current value of alarm_name



208
209
210
# File 'lib/ecs_deploy/auto_scaler.rb', line 208

def alarm_name
  @alarm_name
end

#region ⇒ Object

Returns the value of attribute region

Returns:

  • (Object) —

    the current value of region



208
209
210
# File 'lib/ecs_deploy/auto_scaler.rb', line 208

def region
  @region
end

#state ⇒ Object

Returns the value of attribute state

Returns:

  • (Object) —

    the current value of state



208
209
210
# File 'lib/ecs_deploy/auto_scaler.rb', line 208

def state
  @state
end

#step ⇒ Object

Returns the value of attribute step

Returns:

  • (Object) —

    the current value of step



208
209
210
# File 'lib/ecs_deploy/auto_scaler.rb', line 208

def step
  @step
end

Class Method Details

.alarm_cache ⇒ Object



212
213
214
# File 'lib/ecs_deploy/auto_scaler.rb', line 212

def self.alarm_cache
  @alarm_cache ||= {}
end

.clear_alarm_cache ⇒ Object



216
217
218
# File 'lib/ecs_deploy/auto_scaler.rb', line 216

def self.clear_alarm_cache
  @alarm_cache.clear if @alarm_cache
end

Instance Method Details

#client ⇒ Object



220
221
222
223
224
225
226
# File 'lib/ecs_deploy/auto_scaler.rb', line 220

def client
  self.class.client_table[region] ||= Aws::CloudWatch::Client.new(
    access_key_id: EcsDeploy.config.access_key_id,
    secret_access_key: EcsDeploy.config.secret_access_key,
    region: region
  )
end

#fetch_alarm ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/ecs_deploy/auto_scaler.rb', line 232

def fetch_alarm
  alarm_cache = self.class.alarm_cache
  return alarm_cache[region][alarm_name] if alarm_cache[region] && alarm_cache[region][alarm_name]

  res = client.describe_alarms(alarm_names: [alarm_name])
  raise "Alarm \"#{alarm_name}\" is not found" if res.metric_alarms.empty?
  res.metric_alarms[0].tap do |alarm|
    AutoScaler.logger.debug(alarm.to_json)
    alarm_cache[region] ||= {}
    alarm_cache[region][alarm_name] = alarm
  end
rescue => e
  AutoScaler.error_logger.error(e)
  self.class.client_table[region] = nil
end

#match? ⇒ Boolean

Returns:

  • (Boolean)


228
229
230
# File 'lib/ecs_deploy/auto_scaler.rb', line 228

def match?
  fetch_alarm.state_value == state
end