-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add program abort on k8s_service_watcher fail
Signed-off-by: Alexis Asseman <[email protected]>
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import functools | ||
import logging | ||
|
||
|
||
def async_exit_on_exception(exit_code: int = -1): | ||
"""Returns decorator that logs any exception and exits the program immediately. | ||
The goal of this function is to easily trigger an immediate program abort from any | ||
asynchronous function. | ||
Args: | ||
exit_code (int, optional): Self explanatory. Defaults to -1. | ||
""" | ||
|
||
def decorator(func): | ||
@functools.wraps(func) | ||
async def wrapper(*args, **kwargs): | ||
try: | ||
return await func(*args, **kwargs) | ||
except: | ||
logging.exception("exit_on_exception triggered") | ||
exit(exit_code) | ||
|
||
return wrapper | ||
|
||
return decorator |