Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
error handling for reports
Browse files Browse the repository at this point in the history
  • Loading branch information
adonm committed Dec 8, 2022
1 parent d3700a5 commit 85b15cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions siem_query_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def papermill_report(
- notebook (str, optional): Path to notebook to run. Defaults to "notebooks/report-monthly.ipynb".
- template (str, optional): Path to template to use. Defaults to "notebooks/report-monthly.md".
"""
latest_reports = []
latest_reports, errors = [], []
report_path = settings("datalake_path") / "notebooks" / "reports"
notebook = clean_path(notebook)
localpath = Path(notebook).parent / "notebooks" / Path(notebook).name
Expand Down Expand Up @@ -658,8 +658,17 @@ def papermill_report(
"report_zip": f"{report_path.name}/{report_zip}",
}
logger.debug(f"{alias} report being generated...")
papermill.execute_notebook(tmpnb.name, None, params)
try:
papermill.execute_notebook(tmpnb.name, None, params)
except Exception as exc:
attempted = latest_reports.pop()
attempted["error"] = str(exc)
errors.append(attempted)
(report_path / "latest.json").write_text(json.dumps(latest_reports, indent=2))
if errors:
(report_path / "errors.json").write_text(json.dumps(errors, indent=2))
if agency != "ALL":
return errors
return latest_reports


Expand Down
2 changes: 1 addition & 1 deletion wasoc-notebook

0 comments on commit 85b15cd

Please sign in to comment.