Skip to content
Snippets Groups Projects
Commit 69b30464 authored by Valentin Rigal's avatar Valentin Rigal
Browse files

Support stopping task

parent 6c403bd3
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !2233. Comments created here will be created in the context of that merge request.
......@@ -114,10 +114,18 @@ def run_docker_task(client, task, temp_dir):
task.state = State.Running
task.save()
# 4. Read logs (see agent.setup_logging)
# 4. Read logs
logger.debug("Reading logs from the docker container")
data = b""
for line in container.logs(stream=True):
# Stop a task scheduled to be stopped
task.refresh_from_db()
if task.state == State.Stopping:
container.stop()
task.state = State.Stopped
task.save()
return
data += line
try:
task.logs.s3_object.upload_fileobj(
......@@ -128,6 +136,7 @@ def run_docker_task(client, task, temp_dir):
logger.warning(f"Failed uploading logs for task {task}: {e}")
# 5. Retrieve the state of the container
# Reload container to update `attrs` attribute
container.reload()
exit_code = container.attrs["State"]["ExitCode"]
if exit_code != 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment