Skip to content

Commit

Permalink
Merge pull request #12 from petrjurasek/fail-on-error
Browse files Browse the repository at this point in the history
Add stop on exception
  • Loading branch information
petrjurasek committed May 11, 2021
2 parents cae3d14 + 37b607d commit a63d235
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
artifactory_metrics_updater = ArtifactoryMetricsUpdater(artifactory_api_client)


def exception_handler(loop, context):
loop.default_exception_handler(context)

exception = context.get('exception')
if isinstance(exception, Exception):
logger.error(exception)
loop.stop()


async def update_metrics():
while True:
logger.info('Updating metrics')
Expand All @@ -60,11 +69,14 @@ async def update_metrics():
loop = asyncio.get_event_loop()
start_http_server(app_options.port())

loop.set_exception_handler(exception_handler)
loop.create_task(update_metrics())
try:
loop.run_forever()

except KeyboardInterrupt:
logger.info('Caught keyboard interrupt')
loop.close()
finally:
logger.info('Closing loop')
loop.close()

0 comments on commit a63d235

Please sign in to comment.