Sha256: ce551a06bdf653b93d4655be6ce1b7e61dea7f628088172c2597e6665638b195

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Command
  class PsStop < Base
    NAME = "ps:stop"
    OPTIONS = [
      app_option(required: true),
      workload_option,
      wait_option("workload to be not ready")
    ].freeze
    DESCRIPTION = "Stops workloads in app"
    LONG_DESCRIPTION = <<~DESC
      - Stops workloads in app
    DESC
    EXAMPLES = <<~EX
      ```sh
      # Stops all workloads in app.
      cpl ps:stop -a $APP_NAME

      # Stops a specific workload in app.
      cpl ps:stop -a $APP_NAME -w $WORKLOAD_NAME
      ```
    EX

    def call
      @workloads = [config.options[:workload]] if config.options[:workload]
      @workloads ||= config[:app_workloads] + config[:additional_workloads]

      @workloads.each do |workload|
        step("Stopping workload '#{workload}'") do
          cp.set_workload_suspend(workload, true)
        end
      end

      wait_for_not_ready if config.options[:wait]
    end

    private

    def wait_for_not_ready
      progress.puts

      @workloads.each do |workload|
        step("Waiting for workload '#{workload}' to be not ready", retry_on_failure: true) do
          cp.fetch_workload_deployments(workload)&.dig("items")&.all? do |item|
            !item.dig("status", "ready")
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cpl-1.0.1 lib/command/ps_stop.rb
cpl-1.0.0 lib/command/ps_stop.rb
cpl-0.7.0 lib/command/ps_stop.rb