Skip to content

Commit

Permalink
Add new class for new version of publish reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Dolgolev committed Apr 16, 2021
1 parent 0a892bb commit 835c35b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
43 changes: 39 additions & 4 deletions python/humbug/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import uuid

import requests
from bugout.app import Bugout

from .consent import HumbugConsent
from .system_information import (
Expand Down Expand Up @@ -46,8 +47,7 @@ class Modes(Enum):
DEFAULT = 0
SYNCHRONOUS = 1


class Reporter:
class HumbugReporter:
def __init__(
self,
name: str,
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(

self.is_excepthook_set = False
self.is_loggerhook_set = False

def wait(self) -> None:
concurrent.futures.wait(
self.report_futures, timeout=float(self.timeout_seconds)
Expand All @@ -113,7 +113,7 @@ def system_tags(self) -> List[str]:
tags.append("client:{}".format(self.client_id))

return tags

def publish(self, report: Report, wait: bool = False) -> None:
if not self.consent.check():
return
Expand Down Expand Up @@ -414,3 +414,38 @@ def showtraceback(*args, **kwargs):

ipython_shell.showtraceback = showtraceback
self.setup_excepthook(publish=True, tags=tags)


class Reporter(HumbugReporter):

def publish(self, report: Report, wait: bool = False) -> None:
if not self.consent.check():
return
if self.bugout_token is None or self.bugout_journal_id is None:
return

try:
report.tags = list(set(report.tags))
if wait or self.executor is None:
self.bugout.create_entry(
token=self.bugout_token,
journal_id=self.bugout_journal_id,
title=report.title,
content=report.content,
tags=report.tags,
timeout=self.timeout_seconds,
)
else:
report_future = self.executor.submit(
self.bugout.create_entry,
token=self.bugout_token,
journal_id=self.bugout_journal_id,
title=report.title,
content=report.content,
tags=report.tags,
timeout=self.timeout_seconds,
)
self.report_futures.append(report_future)
except:
pass

2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
name="humbug",
version="0.2.0",
packages=find_packages(),
install_requires=["requests"],
install_requires=["requests","bugout"],
extras_require={
"dev": ["black", "mypy", "wheel"],
"distribute": ["setuptools", "twine", "wheel"],
Expand Down

0 comments on commit 835c35b

Please sign in to comment.