Class: Wrapbox::Runner::Ecs

Inherits:
Object
  • Object
show all
Defined in:
lib/wrapbox/runner/ecs.rb

Defined Under Namespace

Classes: Cli, ContainerAbnormalEnd, ExecutionFailure, ExecutionTimeout, LackResource, LaunchFailure, Parameter

Constant Summary collapse

EXECUTION_RETRY_INTERVAL =
3
WAIT_DELAY =
5
HOST_TERMINATED_REASON_REGEXP =
/Host EC2.*terminated/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Ecs

Returns a new instance of Ecs.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wrapbox/runner/ecs.rb', line 33

def initialize(options)
  @name = options[:name]
  @revision = options[:revision]
  @cluster = options[:cluster]
  @region = options[:region]
  @container_definition = options[:container_definition]
  @additional_container_definitions = options[:additional_container_definitions]
  @task_role_arn = options[:task_role_arn]
  $stdout.sync = true
  @logger = Logger.new($stdout)
end

Instance Attribute Details

#additional_container_definitionsObject (readonly)

Returns the value of attribute additional_container_definitions.



24
25
26
# File 'lib/wrapbox/runner/ecs.rb', line 24

def additional_container_definitions
  @additional_container_definitions
end

#clusterObject (readonly)

Returns the value of attribute cluster.



24
25
26
# File 'lib/wrapbox/runner/ecs.rb', line 24

def cluster
  @cluster
end

#container_definitionObject (readonly)

Returns the value of attribute container_definition.



24
25
26
# File 'lib/wrapbox/runner/ecs.rb', line 24

def container_definition
  @container_definition
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/wrapbox/runner/ecs.rb', line 24

def name
  @name
end

#regionObject (readonly)

Returns the value of attribute region.



24
25
26
# File 'lib/wrapbox/runner/ecs.rb', line 24

def region
  @region
end

#revisionObject (readonly)

Returns the value of attribute revision.



24
25
26
# File 'lib/wrapbox/runner/ecs.rb', line 24

def revision
  @revision
end

#task_role_arnObject (readonly)

Returns the value of attribute task_role_arn.



24
25
26
# File 'lib/wrapbox/runner/ecs.rb', line 24

def task_role_arn
  @task_role_arn
end

Instance Method Details

#run(class_name, method_name, args, container_definition_overrides: {}, **parameters) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/wrapbox/runner/ecs.rb', line 66

def run(class_name, method_name, args, container_definition_overrides: {}, **parameters)
  task_definition = register_task_definition(container_definition_overrides)
  parameter = Parameter.new(**parameters)

  run_task(
    task_definition.task_definition_arn, class_name, method_name, args,
    ["bundle", "exec", "rake", "wrapbox:run"],
    parameter
  )
end

#run_cmd(cmds, container_definition_overrides: {}, **parameters) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/wrapbox/runner/ecs.rb', line 77

def run_cmd(cmds, container_definition_overrides: {}, **parameters)
  task_definition = register_task_definition(container_definition_overrides)
  parameter = Parameter.new(**parameters)

  ths = cmds.map do |cmd|
    Thread.new(cmd) do |c|
      run_task(
        task_definition.task_definition_arn, nil, nil, nil,
        c.split(/\s+/),
        parameter
      )
    end
  end
  ths.each(&:join)
end