Skip to content

Commit

Permalink
Upd loop and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed Nov 18, 2022
1 parent 738746e commit bcf8778
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pylibagent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pylibagent/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.3'
__version__ = '0.1.4'

0 comments on commit bcf8778

Please sign in to comment.