Always pass `loglevel: str` to daemon root task eps
If you want a sub-actor to write console logs (with the right level) the `get_console_log()` call has to be made somewhere during service task startup. Previously this wasn't well formalized nor used (depending on daemon) so passing `loglevel` to the service's root-task-endpoint (eg. `_setup_persistent_brokerd()`) encourages that the daemon's logging is configured during init according to the spawner's requesting logging config. The previous `get_console_log()` call happening inside `maybe_spawn_daemon()` wasn't actually doing anything in the target daemon XD, so obviously remove that and instead passthrough loglevel to the ctx endpoints and service manager methods.pre_overruns_ctxcancelled
parent
6e9d3fb66d
commit
72c98af1d1
|
@ -31,7 +31,6 @@ import tractor
|
||||||
|
|
||||||
from ._util import (
|
from ._util import (
|
||||||
log, # sub-sys logger
|
log, # sub-sys logger
|
||||||
get_console_log,
|
|
||||||
)
|
)
|
||||||
from ..brokers import get_brokermod
|
from ..brokers import get_brokermod
|
||||||
from ._mngr import (
|
from ._mngr import (
|
||||||
|
@ -77,9 +76,6 @@ async def maybe_spawn_daemon(
|
||||||
clients.
|
clients.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
if loglevel:
|
|
||||||
get_console_log(loglevel)
|
|
||||||
|
|
||||||
# serialize access to this section to avoid
|
# serialize access to this section to avoid
|
||||||
# 2 or more tasks racing to create a daemon
|
# 2 or more tasks racing to create a daemon
|
||||||
lock = Services.locks[service_name]
|
lock = Services.locks[service_name]
|
||||||
|
@ -91,10 +87,10 @@ async def maybe_spawn_daemon(
|
||||||
yield portal
|
yield portal
|
||||||
return
|
return
|
||||||
|
|
||||||
log.warning(f"Couldn't find any existing {service_name}")
|
log.warning(
|
||||||
|
f"Couldn't find any existing {service_name}\n"
|
||||||
# TODO: really shouldn't the actor spawning be part of the service
|
'Attempting to spawn new daemon-service..'
|
||||||
# starting method `Services.start_service()` ?
|
)
|
||||||
|
|
||||||
# ask root ``pikerd`` daemon to spawn the daemon we need if
|
# ask root ``pikerd`` daemon to spawn the daemon we need if
|
||||||
# pikerd is not live we now become the root of the
|
# pikerd is not live we now become the root of the
|
||||||
|
@ -114,23 +110,33 @@ async def maybe_spawn_daemon(
|
||||||
# service task for that actor.
|
# service task for that actor.
|
||||||
started: bool
|
started: bool
|
||||||
if pikerd_portal is None:
|
if pikerd_portal is None:
|
||||||
started = await service_task_target(**spawn_args)
|
started = await service_task_target(
|
||||||
|
loglevel=loglevel,
|
||||||
|
**spawn_args,
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# tell the remote `pikerd` to start the target,
|
# request a remote `pikerd` (service manager) to start the
|
||||||
# the target can't return a non-serializable value
|
# target daemon-task, the target can't return
|
||||||
# since it is expected that service startingn is
|
# a non-serializable value since it is expected that service
|
||||||
# non-blocking and the target task will persist running
|
# starting is non-blocking and the target task will persist
|
||||||
# on `pikerd` after the client requesting it's start
|
# running "under" or "within" the `pikerd` actor tree after
|
||||||
# disconnects.
|
# the questing client disconnects. in other words this
|
||||||
|
# spawns a persistent daemon actor that continues to live
|
||||||
|
# for the lifespan of whatever the service manager inside
|
||||||
|
# `pikerd` says it should.
|
||||||
started = await pikerd_portal.run(
|
started = await pikerd_portal.run(
|
||||||
service_task_target,
|
service_task_target,
|
||||||
|
loglevel=loglevel,
|
||||||
**spawn_args,
|
**spawn_args,
|
||||||
)
|
)
|
||||||
|
|
||||||
if started:
|
if started:
|
||||||
log.info(f'Service {service_name} started!')
|
log.info(f'Service {service_name} started!')
|
||||||
|
|
||||||
|
# block until we can discover (by IPC connection) to the newly
|
||||||
|
# spawned daemon-actor and then deliver the portal to the
|
||||||
|
# caller.
|
||||||
async with tractor.wait_for_actor(service_name) as portal:
|
async with tractor.wait_for_actor(service_name) as portal:
|
||||||
lock.release()
|
lock.release()
|
||||||
yield portal
|
yield portal
|
||||||
|
@ -180,8 +186,11 @@ async def spawn_brokerd(
|
||||||
await Services.start_service_task(
|
await Services.start_service_task(
|
||||||
dname,
|
dname,
|
||||||
portal,
|
portal,
|
||||||
|
|
||||||
|
# signature of target root-task endpoint
|
||||||
_setup_persistent_brokerd,
|
_setup_persistent_brokerd,
|
||||||
brokername=brokername,
|
brokername=brokername,
|
||||||
|
loglevel=loglevel,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -243,7 +252,10 @@ async def spawn_emsd(
|
||||||
await Services.start_service_task(
|
await Services.start_service_task(
|
||||||
'emsd',
|
'emsd',
|
||||||
portal,
|
portal,
|
||||||
|
|
||||||
|
# signature of target root-task endpoint
|
||||||
_setup_persistent_emsd,
|
_setup_persistent_emsd,
|
||||||
|
loglevel=loglevel,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -255,10 +267,9 @@ async def maybe_open_emsd(
|
||||||
loglevel: str | None = None,
|
loglevel: str | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
|
||||||
) -> tractor._portal.Portal: # noqa
|
) -> tractor.Portal: # noqa
|
||||||
|
|
||||||
async with maybe_spawn_daemon(
|
async with maybe_spawn_daemon(
|
||||||
|
|
||||||
'emsd',
|
'emsd',
|
||||||
service_task_target=spawn_emsd,
|
service_task_target=spawn_emsd,
|
||||||
spawn_args={'loglevel': loglevel},
|
spawn_args={'loglevel': loglevel},
|
||||||
|
|
|
@ -56,7 +56,7 @@ class Services:
|
||||||
name: str,
|
name: str,
|
||||||
portal: tractor.Portal,
|
portal: tractor.Portal,
|
||||||
target: Callable,
|
target: Callable,
|
||||||
**kwargs,
|
**ctx_kwargs,
|
||||||
|
|
||||||
) -> (trio.CancelScope, tractor.Context):
|
) -> (trio.CancelScope, tractor.Context):
|
||||||
'''
|
'''
|
||||||
|
@ -81,7 +81,7 @@ class Services:
|
||||||
with trio.CancelScope() as cs:
|
with trio.CancelScope() as cs:
|
||||||
async with portal.open_context(
|
async with portal.open_context(
|
||||||
target,
|
target,
|
||||||
**kwargs,
|
**ctx_kwargs,
|
||||||
|
|
||||||
) as (ctx, first):
|
) as (ctx, first):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue