diff --git a/pylibagent/agent.py b/pylibagent/agent.py index 96a509e..ff16cb6 100644 --- a/pylibagent/agent.py +++ b/pylibagent/agent.py @@ -59,6 +59,7 @@ def __init__(self, key: str, version: str): logging.error('missing environment variable `TOKEN`') exit(1) + self._loop: Optional[asyncio.AbstractEventLoop] = None self._get_headers = {'Authorization': f'Bearer {token}'} self._post_headers = {'Content-Type': 'application/json'} self._post_headers.update(self._get_headers) @@ -97,7 +98,7 @@ async def announce(self, asset_name: Optional[str] = None): except Exception as e: msg = str(e) or type(e).__name__ - logging.exception(f'announce failed: {msg}') + logging.error(f'announce failed: {msg}') exit(1) async def send_data(self, check_key: str, data: dict, @@ -154,12 +155,12 @@ def start(self, checks: Iterable[CheckBase], signal.signal(signal.SIGINT, self._stop) signal.signal(signal.SIGTERM, self._stop) + self._loop = asyncio.get_event_loop() try: - asyncio.run(self._start(checks, asset_name)) + self._loop.run_until_complete(self._start(checks, asset_name)) except asyncio.exceptions.CancelledError: - loop = asyncio.get_event_loop() - loop.run_until_complete(loop.shutdown_asyncgens()) - loop.close() + self._loop.run_until_complete(self._loop.shutdown_asyncgens()) + self._loop.close() def _stop(self, signame, *args): logging.warning( diff --git a/pylibagent/version.py b/pylibagent/version.py index 8ce9b36..7525d19 100644 --- a/pylibagent/version.py +++ b/pylibagent/version.py @@ -1 +1 @@ -__version__ = '0.1.3' +__version__ = '0.1.4'