Sha256: 45e93e0a622a415bfa1a8cbbdd2dd011671dba0f7dd4f6652258edfb6ac766c8

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'active_support/core_ext/hash/except'
require 'mikoshi/plan'

module Mikoshi
  class Plan
    class Service < Base
      TASK_DEFINITION_WITH_REVISION = %r{\A\S+:\d+\z}

      def initialize(yaml_path: nil, client: nil)
        super

        if @data[:task_definition].match(TASK_DEFINITION_WITH_REVISION).nil?
          raise ArgumentError, 'task_definition should have revison by numerically.'
        end

        @data.store :service_name, @data[:service]
      end

      def create_service
        @client.create_service(@data.except(:service))
      end

      def update_service
        @client.update_service(@data.except(:service_name))
      end

      def deploy_service
        resp = @client.describe_services(cluster: @data[:cluster], services: [@data[:service]])
        if resp.services.empty?
          create_service
        else
          update_service
        end
      end

      def deployed?
        resp = @client.describe_services(cluster: @data[:cluster], services: [@data[:service]])
        deployment = resp.services.first.deployments.find do |d|
          d.task_definition.end_with?(@data[:task_definition])
        end

        if deployment.running_count == @data[:desired_count]
          true
        else
          false
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mikoshi-0.1.3 lib/mikoshi/plan/service.rb