Add explicit no-docker error and supervisor start task-func

m4_corrections
Tyler Goodlet 2022-02-17 13:32:51 -05:00
parent dcff80131f
commit 6f749c340d
1 changed files with 31 additions and 9 deletions

View File

@ -23,9 +23,11 @@ from typing import (
# Any, # Any,
) )
from contextlib import asynccontextmanager as acm from contextlib import asynccontextmanager as acm
from requests.exceptions import ConnectionError
# import time # import time
import trio import trio
from trio_typing import TaskStatus
import tractor import tractor
import docker import docker
import json import json
@ -75,6 +77,8 @@ triggers:
''' '''
class DockerNotStarted(Exception):
'Prolly you dint start da daemon bruh'
@acm @acm
async def open_docker( async def open_docker(
@ -83,10 +87,16 @@ async def open_docker(
) -> docker.DockerClient: ) -> docker.DockerClient:
client = docker.DockerClient( try:
base_url=url, client = docker.DockerClient(
**kwargs base_url=url,
) if url else docker.from_env(**kwargs) **kwargs
) if url else docker.from_env(**kwargs)
except (
ConnectionError,
docker.errors.DockerException,
):
raise DockerNotStarted('!?!?')
try: try:
yield client yield client
@ -131,7 +141,7 @@ async def open_docker(
@tractor.context @tractor.context
async def open_marketstore_container( async def open_marketstore(
ctx: tractor.Context, ctx: tractor.Context,
**kwargs, **kwargs,
@ -195,15 +205,20 @@ async def open_marketstore_container(
'Failed to start `marketstore` check logs output for deats' 'Failed to start `marketstore` check logs output for deats'
) )
await ctx.started() await ctx.started(cntr.id)
await trio.sleep_forever() await trio.sleep_forever()
finally: finally:
cntr.stop() cntr.stop()
async def main(): async def start_ahab(
task_status: TaskStatus[trio.Event] = trio.TASK_STATUS_IGNORED,
) -> None:
cn_ready = trio.Event()
task_status.started(cn_ready)
async with tractor.open_nursery( async with tractor.open_nursery(
loglevel='runtime', loglevel='runtime',
) as tn: ) as tn:
@ -211,12 +226,19 @@ async def main():
( (
await tn.start_actor('ahab', enable_modules=[__name__]) await tn.start_actor('ahab', enable_modules=[__name__])
).open_context( ).open_context(
open_marketstore_container open_marketstore,
) as (ctx, first), ) as (ctx, first),
): ):
assert not first assert str(first)
# run till cancelled
await trio.sleep_forever() await trio.sleep_forever()
async def main():
await start_ahab()
await trio.sleep_forever()
if __name__ == '__main__': if __name__ == '__main__':
trio.run(main) trio.run(main)