Skip to content
Snippets Groups Projects

Execute docker tasks in RQ

Merged Valentin Rigal requested to merge dummy-tasks into community
1 file
+ 10
1
Compare changes
  • Side-by-side
  • Inline
+ 10
1
@@ -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:
Loading