Handle "fatal" level log msgs in docker super

m4_corrections
Tyler Goodlet 2022-03-30 14:10:15 -04:00
parent a16cd2fe6d
commit 36b8253b66
1 changed files with 7 additions and 38 deletions

View File

@ -24,7 +24,6 @@ from typing import (
# Any, # Any,
) )
from contextlib import asynccontextmanager as acm from contextlib import asynccontextmanager as acm
# import time
import trio import trio
from trio_typing import TaskStatus from trio_typing import TaskStatus
@ -97,6 +96,7 @@ async def open_docker(
base_url=url, base_url=url,
**kwargs **kwargs
) if url else docker.from_env(**kwargs) ) if url else docker.from_env(**kwargs)
yield client yield client
except ( except (
@ -127,43 +127,10 @@ async def open_docker(
finally: finally:
if client: if client:
# for c in client.containers.list():
# c.kill()
client.close() client.close()
# client.api._custom_adapter.close() # client.api._custom_adapter.close()
for c in client.containers.list():
c.kill()
# async def waitfor(
# cntr: Container,
# attr_path: tuple[str],
# expect=None,
# timeout: float = 0.5,
# ) -> Any:
# '''
# Wait for a container's attr value to be set. If ``expect`` is
# provided wait for the value to be set to that value.
# This is an async version of the helper from our ``pytest-dockerctl``
# plugin.
# '''
# def get(val, path):
# for key in path:
# val = val[key]
# return val
# start = time.time()
# while time.time() - start < timeout:
# cntr.reload()
# val = get(cntr.attrs, attr_path)
# if expect is None and val:
# return val
# elif val == expect:
# return val
# else:
# raise TimeoutError("{} failed to be {}, value: \"{}\"".format(
# attr_path, expect if expect else 'not None', val))
@tractor.context @tractor.context
@ -220,7 +187,7 @@ async def open_marketstored(
}, },
mounts=[config_dir_mnt, data_dir_mnt], mounts=[config_dir_mnt, data_dir_mnt],
detach=True, detach=True,
stop_signal='SIGINT', # stop_signal='SIGINT',
init=True, init=True,
# remove=True, # remove=True,
) )
@ -247,7 +214,7 @@ async def open_marketstored(
seen_so_far.add(entry) seen_so_far.add(entry)
if bp_on_msg: if bp_on_msg:
await tractor.breakpoint() await tractor.breakpoint()
getattr(log, level)(f'{msg}') getattr(log, level, log.error)(f'{msg}')
# if "launching tcp listener for all services..." in msg: # if "launching tcp listener for all services..." in msg:
if match in msg: if match in msg:
@ -269,6 +236,8 @@ async def open_marketstored(
) )
await ctx.started(cntr.id) await ctx.started(cntr.id)
# block for the expected "teardown log msg"..
await process_logs_until('exiting...',) await process_logs_until('exiting...',)
except ( except (