Class: Mikoshi::Plan::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/mikoshi/plan/service.rb

Constant Summary collapse

TASK_DEFINITION_WITH_REVISION =
%r{\A\S+:\d+\z}
IGNORE_OPTIONS_WHEN_UPDATE =
%i[client_token load_balancers placement_constraints placement_strategy role service_name].freeze

Instance Attribute Summary

Attributes inherited from Base

#client, #data

Instance Method Summary collapse

Methods inherited from Base

#invoke_hooks

Constructor Details

#initialize(yaml_path: nil, client: nil) ⇒ Service

Returns a new instance of Service.



13
14
15
16
17
18
19
20
21
# File 'lib/mikoshi/plan/service.rb', line 13

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

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

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

Instance Method Details

#create_serviceObject



23
24
25
26
27
28
29
30
# File 'lib/mikoshi/plan/service.rb', line 23

def create_service
  invoke_before_create_hooks

  @client.create_service(@data[:service].except(:service))
  wait_until_services_stable

  invoke_after_create_hooks
end

#deploy_service(message: false) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mikoshi/plan/service.rb', line 41

def deploy_service(message: false)
  @message = message

  case operation
  when :create
    create_service
  when :update
    update_service
  end
rescue StandardError => e
  invoke_failed_hooks
  raise e
end

#update_serviceObject



32
33
34
35
36
37
38
39
# File 'lib/mikoshi/plan/service.rb', line 32

def update_service
  invoke_before_update_hooks

  @client.update_service(@data[:service].except_keys(IGNORE_OPTIONS_WHEN_UPDATE))
  wait_until_services_stable

  invoke_after_update_hooks
end