Sha256: f2def8ac6dce6060167ac22fac11f435c366d38fec13d0c6b3a0aabe46e47fd6

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require "tty-prompt"

module EcsAutoscalingScheduler
  class Cli
    class Index
      def run
        cluster_name = ask_cluster_name
        service_name = ask_service_name(cluster_name)

        scheduled_actions = application_auto_scaling_client.describe_scheduled_actions(
          cluster_name: cluster_name,
          service_name: service_name,
        )

        scheduled_actions.sort_by(&:schedule).each do |a|
          puts "* name: #{a.scheduled_action_name}, min: #{a.scalable_target_action.min_capacity}, max: #{a.scalable_target_action.max_capacity}, schedule: #{a.schedule}, timezone: #{a.timezone}"
        end
      end

      private
        def prompt
          @prompt ||= TTY::Prompt.new
        end

        def ecs_client
          @ecs_client ||= EcsAutoscalingScheduler::Aws::Ecs.new
        end

        def application_auto_scaling_client
          @application_auto_scaling_client ||= EcsAutoscalingScheduler::Aws::ApplicationAutoScaling.new
        end

        def ask_cluster_name
          prompt.select("Which cluster do you want to see?", ecs_client.all_cluster_names, required: true)
        end

        def ask_service_name(cluster)
          prompt.select("Which service do you want to see?", ecs_client.all_service_names(cluster: cluster), required: true)
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ecs_autoscaling_scheduler-0.1.0 lib/ecs_autoscaling_scheduler/cli/index.rb