Class: EcsCmd::RunTask
- Inherits:
-
Object
- Object
- EcsCmd::RunTask
- Defined in:
- lib/ecs_cmd/run_task.rb
Instance Method Summary collapse
-
#initialize(region, cluster, task_def, container_name = nil, command = []) ⇒ RunTask
constructor
A new instance of RunTask.
-
#run ⇒ Object
simply run the task.
Constructor Details
#initialize(region, cluster, task_def, container_name = nil, command = []) ⇒ RunTask
Returns a new instance of RunTask.
6 7 8 9 10 11 12 |
# File 'lib/ecs_cmd/run_task.rb', line 6 def initialize(region, cluster, task_def, container_name = nil, command = []) @client = Aws::ECS::Client.new(region: region) @cluster = cluster @container_name = container_name @task_def = task_def @command = command end |
Instance Method Details
#run ⇒ Object
simply run the task
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ecs_cmd/run_task.rb', line 15 def run puts 'running task...' resp = if @container_name @client.run_task(cluster: @cluster, task_definition: @task_def, overrides: { container_overrides: [{ name: @container_name, command: @command }] }) else @client.run_task(cluster: @cluster, task_definition: @task_def) end task_arn = resp[0][0]['task_arn'] result = begin puts 'waiting for task to complete...' @client.wait_until(:tasks_stopped, cluster: @cluster, tasks: [task_arn]) rescue Aws::Waiters::Errors::WaiterFailed => error puts "failed waiting for task to run: #{error.}" end puts "task ended with exit code #{result[0][0]['containers'][0]['exit_code']}" # return exit code raise 'task appears to have failed, check container logs' if result[0][0]['containers'][0]['exit_code'] != 0 end |