Sha256: 7d41113b2a7e6b37a1fc2864eec336229059e8ee3f2c4c6140e555275d39b061

Contents?: true

Size: 1.42 KB

Versions: 15

Compression:

Stored size: 1.42 KB

Contents

require 'shipitron'
require 'shipitron/ecs_client'

# Note: This is a best effort client side check to make sure there
# isn't a deploy running.  The server side check has more guarantees.

module Shipitron
  module Client
    class EnsureDeployNotRunning
      include Metaractor
      include EcsClient

      required :clusters
      optional :simulate

      def call
        return if simulate?

        clusters.each do |cluster|
          %w[PENDING RUNNING].each do |status|
            begin
              response = ecs_client(region: cluster.region).list_tasks(
                cluster: cluster.name,
                started_by: 'shipitron',
                max_results: 1,
                desired_status: status
              )
              if !response.task_arns.empty?
                fail_with_errors!(messages: [
                  'Shipitron says "THERE CAN BE ONLY ONE"',
                  'Deploy is already running.'
                ])
              end
            rescue Aws::ECS::Errors::ClusterNotFoundException
              fail_with_errors!(messages: [
                'Shipitron says "PUNY HUMAN IS MISSING A CLUSTER"',
                "Cluster '#{cluster.name}' not found in region #{cluster.region}."
              ])
            end
          end
        end
      end

      private
      def clusters
        context.clusters
      end

      def simulate?
        context.simulate == true
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
shipitron-1.2.1 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-1.2.0 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-1.1.0 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-1.0.1 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-1.0.0 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.4.1 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.4.0 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.3.5 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.3.4 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.3.3 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.3.1 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.3.0 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.2.2 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.2.1 lib/shipitron/client/ensure_deploy_not_running.rb
shipitron-0.2.0 lib/shipitron/client/ensure_deploy_not_running.rb