Class: EcsDeployer::Service::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs_deployer/service/client.rb

Constant Summary collapse

LOG_SEPARATOR =
'-' * 96

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, logger, aws_options = {}) ⇒ EcsDeployer::Service::Client

Parameters:

  • cluster (String)
  • logger (Logger)
  • aws_options (Hash) (defaults to: {})


14
15
16
17
18
19
20
21
22
23
# File 'lib/ecs_deployer/service/client.rb', line 14

def initialize(cluster, logger, aws_options = {})
  @cluster = cluster
  @logger = logger

  @ecs = Aws::ECS::Client.new(aws_options)
  @task = EcsDeployer::Task::Client.new(aws_options)

  @wait_timeout = 900
  @polling_interval = 20
end

Instance Attribute Details

#polling_intervalObject

Returns the value of attribute polling_interval.



8
9
10
# File 'lib/ecs_deployer/service/client.rb', line 8

def polling_interval
  @polling_interval
end

#wait_timeoutObject

Returns the value of attribute wait_timeout.



8
9
10
# File 'lib/ecs_deployer/service/client.rb', line 8

def wait_timeout
  @wait_timeout
end

Instance Method Details

#exist?(service) ⇒ Bool

Parameters:

  • service (String)

Returns:

  • (Bool)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ecs_deployer/service/client.rb', line 42

def exist?(service)
  status = nil
  result = @ecs.describe_services(
    cluster: @cluster,
    services: [service]
  )
  result[:services].each do |svc|
    next unless svc[:service_name] == service && svc[:status] == 'ACTIVE'
    status = svc
    break
  end

  status.nil? ? false : true
end

#update(service, task_definition = nil, wait = true) ⇒ Aws::ECS::Types::Service

Parameters:

  • service (String)
  • task_definition (Aws::ECS::Types::TaskDefinition) (defaults to: nil)

Returns:

  • (Aws::ECS::Types::Service)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ecs_deployer/service/client.rb', line 28

def update(service, task_definition = nil, wait = true)
  task_definition = @task.register_clone(@cluster, service) if task_definition.nil?
  result = @ecs.update_service(
    cluster: @cluster,
    service: service,
    task_definition: task_definition[:family] + ':' + task_definition[:revision].to_s
  )

  wait_for_deploy(service, result.service.task_definition) if wait
  result.service
end