Class: EcsDeploy::AutoScaler::TriggerConfig

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigBase

#initialize

Instance Attribute Details

#alarm_nameObject

Returns the value of attribute alarm_name

Returns:

  • (Object)

    the current value of alarm_name



268
269
270
# File 'lib/ecs_deploy/auto_scaler.rb', line 268

def alarm_name
  @alarm_name
end

#regionObject

Returns the value of attribute region

Returns:

  • (Object)

    the current value of region



268
269
270
# File 'lib/ecs_deploy/auto_scaler.rb', line 268

def region
  @region
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



268
269
270
# File 'lib/ecs_deploy/auto_scaler.rb', line 268

def state
  @state
end

#stepObject

Returns the value of attribute step

Returns:

  • (Object)

    the current value of step



268
269
270
# File 'lib/ecs_deploy/auto_scaler.rb', line 268

def step
  @step
end

Instance Method Details

#clear_clientObject



279
280
281
# File 'lib/ecs_deploy/auto_scaler.rb', line 279

def clear_client
  Thread.current["ecs_auto_scaler_cloud_watch_#{region}"] = nil
end

#clientObject



271
272
273
274
275
276
277
# File 'lib/ecs_deploy/auto_scaler.rb', line 271

def client
  Thread.current["ecs_auto_scaler_cloud_watch_#{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_alarmObject



287
288
289
290
291
292
293
294
295
296
297
# File 'lib/ecs_deploy/auto_scaler.rb', line 287

def fetch_alarm
  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.alarm_name} state is #{alarm.state_value}")
  end
rescue => e
  AutoScaler.error_logger.error(e)
  clear_client
end

#match?Boolean

Returns:

  • (Boolean)


283
284
285
# File 'lib/ecs_deploy/auto_scaler.rb', line 283

def match?
  fetch_alarm.state_value == state
end