Skip to content

Commit

Permalink
Merge pull request #44 from nipreps/doc/track-exit
Browse files Browse the repository at this point in the history
DOC: Expose `track_exit()`, allow keyword arguments
  • Loading branch information
mgxd authored Oct 30, 2023
2 parents 3ad9041 + dd3b1a9 commit 33b0d5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ If no end date is specified, the current datetime is used.

</details>


#### 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:
Expand Down
16 changes: 11 additions & 5 deletions migas/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 33b0d5c

Please sign in to comment.