Class: Barbeque::Executor::Hako
- Inherits:
-
Object
- Object
- Barbeque::Executor::Hako
- Defined in:
- lib/barbeque/executor/hako.rb
Defined Under Namespace
Classes: HakoCommandError
Instance Attribute Summary collapse
-
#hako_s3_client ⇒ Object
readonly
Returns the value of attribute hako_s3_client.
Instance Method Summary collapse
-
#initialize(hako_dir:, hako_env: {}, yaml_dir: nil, definition_dir: nil, oneshot_notification_prefix:) ⇒ Hako
constructor
A new instance of Hako.
- #poll_execution(job_execution) ⇒ Object
- #poll_retry(job_retry) ⇒ Object
- #start_execution(job_execution, envs) ⇒ Object
- #start_retry(job_retry, envs) ⇒ Object
Constructor Details
#initialize(hako_dir:, hako_env: {}, yaml_dir: nil, definition_dir: nil, oneshot_notification_prefix:) ⇒ Hako
Returns a new instance of Hako.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/barbeque/executor/hako.rb', line 19 def initialize(hako_dir:, hako_env: {}, yaml_dir: nil, definition_dir: nil, oneshot_notification_prefix:) @hako_dir = hako_dir @hako_env = hako_env @definition_dir = if definition_dir definition_dir elsif yaml_dir warn 'yaml_dir option is renamed to definition_dir. Please update config/barbeque.yml' yaml_dir else raise ArgumentError.new('definition_dir is required') end @hako_s3_client = HakoS3Client.new(oneshot_notification_prefix) end |
Instance Attribute Details
#hako_s3_client ⇒ Object (readonly)
Returns the value of attribute hako_s3_client.
13 14 15 |
# File 'lib/barbeque/executor/hako.rb', line 13 def hako_s3_client @hako_s3_client end |
Instance Method Details
#poll_execution(job_execution) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/barbeque/executor/hako.rb', line 80 def poll_execution(job_execution) hako_task = Barbeque::EcsHakoTask.find_by!(message_id: job_execution.) task = @hako_s3_client.get_stopped_result(hako_task) if task status = :failed task.containers.each do |container| if container.name == 'app' status = container.exit_code == 0 ? :success : :failed end end job_execution.update!(status: status, finished_at: task.stopped_at) Barbeque::SlackNotifier.notify_job_execution(job_execution) if status == :failed job_execution.retry_if_possible! end end end |
#poll_retry(job_retry) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/barbeque/executor/hako.rb', line 99 def poll_retry(job_retry) hako_task = Barbeque::EcsHakoTask.find_by!(message_id: job_retry.) job_execution = job_retry.job_execution task = @hako_s3_client.get_stopped_result(hako_task) if task status = :failed task.containers.each do |container| if container.name == 'app' status = container.exit_code == 0 ? :success : :failed end end Barbeque::ApplicationRecord.transaction do job_retry.update!(status: status, finished_at: task.stopped_at) job_execution.update!(status: status) end Barbeque::SlackNotifier.notify_job_retry(job_retry) if status == :failed job_execution.retry_if_possible! end end end |
#start_execution(job_execution, envs) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/barbeque/executor/hako.rb', line 36 def start_execution(job_execution, envs) docker_image = DockerImage.new(job_execution.job_definition.app.docker_image) cmd = build_hako_oneshot_command(docker_image, job_execution.job_definition.command, envs) stdout, stderr, status = Bundler.with_clean_env { Open3.capture3(@hako_env, *cmd, chdir: @hako_dir) } if status.success? cluster, task_arn = extract_task_info(stdout) Barbeque::EcsHakoTask.create!(message_id: job_execution., cluster: cluster, task_arn: task_arn) Barbeque::ExecutionLog.try_save_stdout_and_stderr(job_execution, stdout, stderr) job_execution.update!(status: :running) else Barbeque::ExecutionLog.try_save_stdout_and_stderr(job_execution, stdout, stderr) job_execution.update!(status: :failed, finished_at: Time.zone.now) Barbeque::SlackNotifier.notify_job_execution(job_execution) job_execution.retry_if_possible! end end |
#start_retry(job_retry, envs) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/barbeque/executor/hako.rb', line 55 def start_retry(job_retry, envs) job_execution = job_retry.job_execution docker_image = DockerImage.new(job_execution.job_definition.app.docker_image) cmd = build_hako_oneshot_command(docker_image, job_execution.job_definition.command, envs) stdout, stderr, status = Bundler.with_clean_env { Open3.capture3(@hako_env, *cmd, chdir: @hako_dir) } if status.success? cluster, task_arn = extract_task_info(stdout) Barbeque::EcsHakoTask.create!(message_id: job_retry., cluster: cluster, task_arn: task_arn) Barbeque::ExecutionLog.try_save_stdout_and_stderr(job_retry, stdout, stderr) Barbeque::ApplicationRecord.transaction do job_execution.update!(status: :retried) job_retry.update!(status: :running) end else Barbeque::ExecutionLog.try_save_stdout_and_stderr(job_retry, stdout, stderr) Barbeque::ApplicationRecord.transaction do job_retry.update!(status: :failed, finished_at: Time.zone.now) job_execution.update!(status: :failed) end Barbeque::SlackNotifier.notify_job_retry(job_retry) job_execution.retry_if_possible! end end |