10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/ecs_autoscaling_scheduler/cli/destroy_outdated.rb', line 10
def run(option)
cluster_name = option.cluster_name || ask_cluster_name
service_name = option.service_name || ask_service_name(cluster_name)
scheduled_actions = application_auto_scaling_client.describe_scheduled_actions(cluster_name: cluster_name, service_name: service_name)
if scheduled_actions.length == 0
puts "There is no scheduled action."
return
end
now = Time.now
outdated_scheduled_actions = scheduled_actions.filter do |scheduled_action|
timezone = TZInfo::Timezone.get(scheduled_action.timezone)
time_local = Time.parse(scheduled_action.schedule)
time_utc = timezone.local_to_utc(time_local)
time_utc < now
end
if outdated_scheduled_actions.length == 0
puts "There is no outdated scheduled action."
return
end
if ask_ok(outdated_scheduled_actions.length)
outdated_scheduled_actions.each do |outdated_scheduled_action|
puts "Destroying #{outdated_scheduled_action.scheduled_action_name}..."
application_auto_scaling_client.delete_scheduled_action(
cluster_name: cluster_name,
service_name: service_name,
scheduled_action_name: outdated_scheduled_action.scheduled_action_name,
)
end
puts "Destroy complete."
else
puts "Destroy cancelled."
end
end
|