From dd3b1a93d5d86309b7ac5d938ca23d234a047ad1 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 30 Oct 2023 12:04:01 -0400 Subject: [PATCH] DOC: Expose `track_exit()`, allow keyword arguments --- README.md | 6 ++++++ migas/helpers.py | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0cc3adf..6f1f4ab 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,12 @@ If no end date is specified, the current datetime is used. + +#### migas.track_exit() + +Register an exit function to send a final ping upon termination of the Python interpretter. +The inputs are equivalent to `add_project()`. + ## User Control `migas` can controlled by the following environmental variables: diff --git a/migas/helpers.py b/migas/helpers.py index f2c2620..2b82df6 100644 --- a/migas/helpers.py +++ b/migas/helpers.py @@ -6,11 +6,17 @@ from migas.operations import add_project -def track_exit(project: str, version: str, error_funcs: dict | None = None) -> None: - atexit.register(_final_breadcrumb, project, version, error_funcs) - -def _final_breadcrumb(project: str, version: str, error_funcs: dict | None = None) -> dict: - kwargs = _inspect_error(error_funcs) +def track_exit(project: str, version: str, error_funcs: dict | None = None, **kwargs) -> None: + atexit.register(_final_breadcrumb, project, version, error_funcs, **kwargs) + +def _final_breadcrumb( + project: str, + version: str, + error_funcs: dict | None = None, + **ping_kwargs, +) -> dict: + status = _inspect_error(error_funcs) + kwargs = {**ping_kwargs, **status} return add_project(project, version, **kwargs)