Class: Barbeque::Executor::Docker
- Inherits:
-
Object
- Object
- Barbeque::Executor::Docker
show all
- Defined in:
- lib/barbeque/executor/docker.rb
Defined Under Namespace
Classes: DockerCommandError
Instance Method Summary
collapse
Constructor Details
#initialize(_options) ⇒ Docker
Returns a new instance of Docker.
12
13
|
# File 'lib/barbeque/executor/docker.rb', line 12
def initialize(_options)
end
|
Instance Method Details
#poll_execution(job_execution) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/barbeque/executor/docker.rb', line 57
def poll_execution(job_execution)
container = Barbeque::DockerContainer.find_by!(message_id: job_execution.message_id)
info = inspect_container(container.container_id)
if info['State'] && info['State']['Status'] != 'running'
finished_at = Time.zone.parse(info['State']['FinishedAt'])
exit_code = info['State']['ExitCode']
job_execution.update!(status: exit_code == 0 ? :success : :failed, finished_at: finished_at)
stdout, stderr = get_logs(container.container_id)
Barbeque::ExecutionLog.save_stdout_and_stderr(job_execution, stdout, stderr)
Barbeque::SlackNotifier.notify_job_execution(job_execution)
if exit_code != 0
job_execution.retry_if_possible!
end
end
end
|
#poll_retry(job_retry) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/barbeque/executor/docker.rb', line 75
def poll_retry(job_retry)
container = Barbeque::DockerContainer.find_by!(message_id: job_retry.message_id)
job_execution = job_retry.job_execution
info = inspect_container(container.container_id)
if info['State'] && info['State']['Status'] != 'running'
finished_at = Time.zone.parse(info['State']['FinishedAt'])
exit_code = info['State']['ExitCode']
status = exit_code == 0 ? :success : :failed
Barbeque::ApplicationRecord.transaction do
job_retry.update!(status: status, finished_at: finished_at)
job_execution.update!(status: status)
end
stdout, stderr = get_logs(container.container_id)
Barbeque::ExecutionLog.save_stdout_and_stderr(job_retry, stdout, stderr)
Barbeque::SlackNotifier.notify_job_retry(job_retry)
if status == :failed
job_execution.retry_if_possible!
end
end
end
|
#start_execution(job_execution, envs) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/barbeque/executor/docker.rb', line 17
def start_execution(job_execution, envs)
docker_image = DockerImage.new(job_execution.job_definition.app.docker_image)
cmd = build_docker_run_command(docker_image, job_execution.job_definition.command, envs)
stdout, stderr, status = Open3.capture3(*cmd)
if status.success?
Barbeque::DockerContainer.create!(message_id: job_execution.message_id, container_id: stdout.chomp)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/barbeque/executor/docker.rb', line 34
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_docker_run_command(docker_image, job_execution.job_definition.command, envs)
stdout, stderr, status = Open3.capture3(*cmd)
if status.success?
Barbeque::DockerContainer.create!(message_id: job_retry.message_id, container_id: stdout.chomp)
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
|