ecs_autoscaling_scheduler 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91c16cfe5a2d8c2ba3c4abc54eb44bcbd40c3cc1c7f3c44ed6fb2c7988df7544
4
- data.tar.gz: 100af8f8b90585cea334c1cc16e24c826ea938797d59781d2e723cd7909c790b
3
+ metadata.gz: 5ccd9d631b1f3edd4f52107d1a47e96aadc3e244a2c6b3dbd5d7cf6e264309f0
4
+ data.tar.gz: 8ba3e8ef12cafa1b8f99545889b59d7f985a763efd56f58e4a37014b52343984
5
5
  SHA512:
6
- metadata.gz: f3b22b22059cac484bfe7ebcf3fdd375711336936c1c91252b14d4eb944d5e37213891f1371e7f67c7db5374aa5230d96580f78b3e06078b011f366634ef4646
7
- data.tar.gz: 92f56ba9a7563ce49ffe7c21946bec22e620a1169392e92d59c0891a72aa822887ba465d08eee6f032fa8e8c24ba18f1fff625bbc4c682f9a08a61e78687ec31
6
+ metadata.gz: 524a3610ada957361008ead315e6a242ced393bf4cd56e96479ebce3eb2f720ec73889ed44cbfb12c4dba5a77bd3456b9464a68b85cd68155ebdd99920162075
7
+ data.tar.gz: 42b032a599516392aa54d8f27950ef2e66d6294719d6e8141ce2deee5d489ef9b7d19918f4b658d47c38feb04a34ea94976803e72af8635f58bf18bdcfff1ff3
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.10
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2025-03-19
4
+
5
+ ### Added
6
+
7
+ - Add `destroy_outdated` command to delete all outdated schedules.
8
+ - Add CLI Options. See `ecs_autoscaling_scheduler --help` for all available opitons.
9
+
3
10
  ## [0.1.0] - 2022-08-09
4
11
 
5
12
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ecs_autoscaling_scheduler (0.1.0)
4
+ ecs_autoscaling_scheduler (0.2.0)
5
5
  activesupport (~> 6.1)
6
6
  aws-sdk-applicationautoscaling (~> 1.62)
7
7
  aws-sdk-ecs (~> 1.100)
@@ -149,6 +149,7 @@ GEM
149
149
 
150
150
  PLATFORMS
151
151
  arm64-darwin-21
152
+ arm64-darwin-23
152
153
 
153
154
  DEPENDENCIES
154
155
  ecs_autoscaling_scheduler!
@@ -158,4 +159,4 @@ DEPENDENCIES
158
159
  rubocop-rails_config
159
160
 
160
161
  BUNDLED WITH
161
- 2.2.32
162
+ 2.4.12
data/README.md CHANGED
@@ -23,8 +23,8 @@ AWS_PROFILE=foo ecs_autoscaling_scheduler
23
23
 
24
24
  ## Motivations
25
25
 
26
- - At this time, we can configure "target-tracking scaling" or "step scaling" for your ECS service through the AWS Management Console or copilot-cli, but somehow can not configure "scheduled scaling" (even though they have APIs to set up scheduled scaling).
27
- - Target-tracking scaling or step scaling is not enough for a spike access.
26
+ - As of August 2022, there was no way to configure Scheduled Scaling from the AWS Management Console (even though they have APIs to set it up).
27
+ - It is now possible to configure it, so perhaps this tool is no longer needed.
28
28
 
29
29
  ## Development
30
30
 
@@ -7,14 +7,14 @@ require "active_support/time"
7
7
  module EcsAutoscalingScheduler
8
8
  class Cli
9
9
  class Create
10
- def run
11
- cluster_name = ask_cluster_name
12
- service_name = ask_service_name(cluster_name)
13
- timezone = ask_timezone
14
- schedule = ask_schedule
15
- min_capacity = ask_min_capacity
16
- max_capacity = ask_max_capacity
17
- scheduled_action_name = ask_scheduled_action_name(schedule, min_capacity, max_capacity)
10
+ def run(option)
11
+ cluster_name = option.cluster_name || ask_cluster_name
12
+ service_name = option.service_name || ask_service_name(cluster_name)
13
+ timezone = option.timezone || ask_timezone
14
+ schedule = option.schedule || ask_schedule
15
+ min_capacity = option.min_capacity || ask_min_capacity
16
+ max_capacity = option.max_capacity || ask_max_capacity
17
+ scheduled_action_name = option.scheduled_action_name || ask_scheduled_action_name(schedule, min_capacity, max_capacity)
18
18
 
19
19
  if ask_ok
20
20
  application_auto_scaling_client.put_scheduled_action(
@@ -5,9 +5,9 @@ require "tty-prompt"
5
5
  module EcsAutoscalingScheduler
6
6
  class Cli
7
7
  class Destroy
8
- def run
9
- cluster_name = ask_cluster_name
10
- service_name = ask_service_name(cluster_name)
8
+ def run(option)
9
+ cluster_name = option.cluster_name || ask_cluster_name
10
+ service_name = option.service_name || ask_service_name(cluster_name)
11
11
 
12
12
  scheduled_action_names = application_auto_scaling_client.describe_scheduled_actions(cluster_name: cluster_name, service_name: service_name).map(&:scheduled_action_name)
13
13
  if scheduled_action_names.length == 0
@@ -15,7 +15,7 @@ module EcsAutoscalingScheduler
15
15
  return
16
16
  end
17
17
 
18
- scheduled_action_name = ask_scheduled_action_name(scheduled_action_names)
18
+ scheduled_action_name = option.scheduled_action_name || ask_scheduled_action_name(scheduled_action_names)
19
19
 
20
20
  if ask_ok
21
21
  application_auto_scaling_client.delete_scheduled_action(
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-prompt"
4
+ require "time"
5
+ require "tzinfo"
6
+
7
+ module EcsAutoscalingScheduler
8
+ class Cli
9
+ class DestroyOutdated
10
+ def run(option)
11
+ cluster_name = option.cluster_name || ask_cluster_name
12
+ service_name = option.service_name || ask_service_name(cluster_name)
13
+
14
+ scheduled_actions = application_auto_scaling_client.describe_scheduled_actions(cluster_name: cluster_name, service_name: service_name)
15
+ if scheduled_actions.length == 0
16
+ puts "There is no scheduled action."
17
+ return
18
+ end
19
+
20
+ now = Time.now
21
+ outdated_scheduled_actions = scheduled_actions.filter do |scheduled_action|
22
+ timezone = TZInfo::Timezone.get(scheduled_action.timezone)
23
+ time_local = Time.parse(scheduled_action.schedule)
24
+ time_utc = timezone.local_to_utc(time_local)
25
+ time_utc < now
26
+ end
27
+ if outdated_scheduled_actions.length == 0
28
+ puts "There is no outdated scheduled action."
29
+ return
30
+ end
31
+
32
+ if ask_ok(outdated_scheduled_actions.length)
33
+ outdated_scheduled_actions.each do |outdated_scheduled_action|
34
+ puts "Destroying #{outdated_scheduled_action.scheduled_action_name}..."
35
+ application_auto_scaling_client.delete_scheduled_action(
36
+ cluster_name: cluster_name,
37
+ service_name: service_name,
38
+ scheduled_action_name: outdated_scheduled_action.scheduled_action_name,
39
+ )
40
+ end
41
+ puts "Destroy complete."
42
+ else
43
+ puts "Destroy cancelled."
44
+ end
45
+ end
46
+
47
+ private
48
+ def prompt
49
+ @prompt ||= TTY::Prompt.new
50
+ end
51
+
52
+ def ecs_client
53
+ @ecs_client ||= EcsAutoscalingScheduler::Aws::Ecs.new
54
+ end
55
+
56
+ def application_auto_scaling_client
57
+ @application_auto_scaling_client ||= EcsAutoscalingScheduler::Aws::ApplicationAutoScaling.new
58
+ end
59
+
60
+ def ask_cluster_name
61
+ prompt.select("Which cluster do you want to manage?", ecs_client.all_cluster_names, required: true)
62
+ end
63
+
64
+ def ask_service_name(cluster)
65
+ prompt.select("Which service do you want to manage?", ecs_client.all_service_names(cluster: cluster), required: true)
66
+ end
67
+
68
+ def ask_ok(num_outdated)
69
+ prompt.yes?("Do you want to destroy all (#{num_outdated}) outdated scheduled actions?", required: true)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -5,9 +5,9 @@ require "tty-prompt"
5
5
  module EcsAutoscalingScheduler
6
6
  class Cli
7
7
  class Index
8
- def run
9
- cluster_name = ask_cluster_name
10
- service_name = ask_service_name(cluster_name)
8
+ def run(option)
9
+ cluster_name = option.cluster_name || ask_cluster_name
10
+ service_name = option.service_name || ask_service_name(cluster_name)
11
11
 
12
12
  scheduled_actions = application_auto_scaling_client.describe_scheduled_actions(
13
13
  cluster_name: cluster_name,
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EcsAutoscalingScheduler
4
+ class Cli
5
+ class Option
6
+ attr_reader :command
7
+ attr_reader :cluster_name
8
+ attr_reader :service_name
9
+ attr_reader :timezone
10
+ attr_reader :schedule
11
+ attr_reader :min_capacity
12
+ attr_reader :max_capacity
13
+ attr_reader :scheduled_action_name
14
+
15
+ def initialize(**kwargs)
16
+ @command = kwargs[:command]
17
+ @cluster_name = kwargs[:cluster_name]
18
+ @service_name = kwargs[:service_name]
19
+ @timezone = kwargs[:timezone]
20
+ @schedule = kwargs[:schedule]
21
+ @min_capacity = kwargs[:min_capacity]
22
+ @max_capacity = kwargs[:max_capacity]
23
+ @scheduled_action_name = kwargs[:scheduled_action_name]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -3,9 +3,12 @@
3
3
  require_relative "cli/index"
4
4
  require_relative "cli/create"
5
5
  require_relative "cli/destroy"
6
+ require_relative "cli/destroy_outdated"
6
7
  require_relative "cli/bye"
8
+ require_relative "cli/option"
7
9
 
8
10
  require "tty-prompt"
11
+ require "optparse"
9
12
 
10
13
  module EcsAutoscalingScheduler
11
14
  class Cli
@@ -13,23 +16,44 @@ module EcsAutoscalingScheduler
13
16
  index: "index",
14
17
  create: "create",
15
18
  destroy: "destroy",
19
+ destroy_outdated: "destroy_outdated",
16
20
  bye: "bye",
17
21
  }
18
22
 
19
23
  def run
20
- case ask_command
24
+ option = parse_option
25
+ case option.command || ask_command
21
26
  when COMMAND[:index]
22
- Index.new.run
27
+ Index.new.run(option)
23
28
  when COMMAND[:create]
24
- Create.new.run
29
+ Create.new.run(option)
25
30
  when COMMAND[:destroy]
26
- Destroy.new.run
31
+ Destroy.new.run(option)
32
+ when COMMAND[:destroy_outdated]
33
+ DestroyOutdated.new.run(option)
27
34
  else
28
35
  Bye.new.run
29
36
  end
30
37
  end
31
38
 
32
39
  private
40
+ def parse_option
41
+ option_params = {}
42
+
43
+ OptionParser.new do |opts|
44
+ opts.on("-x VALUE", "--command VALUE") { |v| option_params[:command] = v }
45
+ opts.on("-c VALUE", "--cluster-name VALUE") { |v| option_params[:cluster_name] = v }
46
+ opts.on("-s VALUE", "--service-name VALUE") { |v| option_params[:service_name] = v }
47
+ opts.on("-z VALUE", "--timezone VALUE") { |v| option_params[:timezone] = v }
48
+ opts.on("-t VALUE", "--schedule VALUE") { |v| option_params[:schedule] = Time.parse(v) }
49
+ opts.on("-m VALUE", "--min-capacity VALUE", Integer) { |v| option_params[:min_capacity] = v }
50
+ opts.on("-M VALUE", "--max-capacity VALUE", Integer) { |v| option_params[:max_capacity] = v }
51
+ opts.on("-n VALUE", "--scheduled-action-name VALUE") { |v| option_params[:scheduled_action_name] = v }
52
+ end.parse!
53
+
54
+ Option.new(**option_params)
55
+ end
56
+
33
57
  def prompt
34
58
  @prompt ||= TTY::Prompt.new
35
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EcsAutoscalingScheduler
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs_autoscaling_scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - megane42
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-09 00:00:00.000000000 Z
11
+ date: 2025-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-applicationautoscaling
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description:
83
+ description:
84
84
  email:
85
85
  - ''
86
86
  executables:
@@ -90,6 +90,7 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - ".rspec"
92
92
  - ".rubocop.yml"
93
+ - ".ruby-version"
93
94
  - CHANGELOG.md
94
95
  - Gemfile
95
96
  - Gemfile.lock
@@ -108,7 +109,9 @@ files:
108
109
  - lib/ecs_autoscaling_scheduler/cli/bye.rb
109
110
  - lib/ecs_autoscaling_scheduler/cli/create.rb
110
111
  - lib/ecs_autoscaling_scheduler/cli/destroy.rb
112
+ - lib/ecs_autoscaling_scheduler/cli/destroy_outdated.rb
111
113
  - lib/ecs_autoscaling_scheduler/cli/index.rb
114
+ - lib/ecs_autoscaling_scheduler/cli/option.rb
112
115
  - lib/ecs_autoscaling_scheduler/version.rb
113
116
  homepage: https://github.com/megane42/ecs_autoscaling_scheduler/
114
117
  licenses:
@@ -118,7 +121,7 @@ metadata:
118
121
  homepage_uri: https://github.com/megane42/ecs_autoscaling_scheduler/
119
122
  source_code_uri: https://github.com/megane42/ecs_autoscaling_scheduler/
120
123
  changelog_uri: https://github.com/megane42/ecs_autoscaling_scheduler/blob/master/CHANGELOG.md
121
- post_install_message:
124
+ post_install_message:
122
125
  rdoc_options: []
123
126
  require_paths:
124
127
  - lib
@@ -134,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
137
  version: '0'
135
138
  requirements: []
136
139
  rubygems_version: 3.0.3.1
137
- signing_key:
140
+ signing_key:
138
141
  specification_version: 4
139
142
  summary: A CLI to manage scheduled scaling for ECS services
140
143
  test_files: []