mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-22 07:48:12 +08:00
registering entry points for sentry and rollbar plugins, maintained in seperate repos. start of a generic error handling implementation
This commit is contained in:
+44
-12
@@ -9,6 +9,7 @@ from django.conf import settings
|
||||
|
||||
# external
|
||||
import os
|
||||
import pkg_resources
|
||||
|
||||
# optional
|
||||
try:
|
||||
@@ -141,8 +142,8 @@ class Conf(object):
|
||||
# The redis stats key
|
||||
Q_STAT = 'django_q:{}:cluster'.format(PREFIX)
|
||||
|
||||
# Optional Rollbar key
|
||||
ROLLBAR = conf.get('rollbar', {})
|
||||
# Optional error reporting setup
|
||||
ERROR_REPORTER = conf.get('error_reporter', {})
|
||||
|
||||
# OSX doesn't implement qsize because of missing sem_getvalue()
|
||||
try:
|
||||
@@ -177,17 +178,48 @@ if not logger.handlers:
|
||||
handler.setFormatter(formatter)
|
||||
logger.addHandler(handler)
|
||||
|
||||
# rollbar
|
||||
if Conf.ROLLBAR:
|
||||
rollbar_conf = deepcopy(Conf.ROLLBAR)
|
||||
try:
|
||||
import rollbar
|
||||
rollbar.init(rollbar_conf.pop('access_token'), environment=rollbar_conf.pop('environment'), **rollbar_conf)
|
||||
except ImportError:
|
||||
rollbar = None
|
||||
|
||||
else:
|
||||
rollbar = None
|
||||
# Error Reporting Interface
|
||||
class ErrorReporter(object):
|
||||
|
||||
# initialize with iterator of reporters (better name, targets?)
|
||||
def __init__(self, reporters):
|
||||
self.targets = [target for target in reporters]
|
||||
|
||||
# report error to all configured targets
|
||||
def report(self):
|
||||
for t in self.targets:
|
||||
t.report()
|
||||
|
||||
|
||||
# error reporting setup (sentry or rollbar)
|
||||
if Conf.ERROR_REPORTER:
|
||||
error_conf = deepcopy(Conf.ERROR_REPORTER)
|
||||
try:
|
||||
reporters = []
|
||||
# iterate through the configured error reporters,
|
||||
# and instantiate an ErrorReporter using the provided config
|
||||
for name, conf in error_conf.items():
|
||||
Reporter = pkg_resources.iter_entry_points(
|
||||
'djangoq.errorreporters', name).load()
|
||||
e = Reporter(**conf)
|
||||
reporters.append(e)
|
||||
error_reporter = ErrorReporter(reporters)
|
||||
except ImportError:
|
||||
error_reporter = None
|
||||
|
||||
# # rollbar
|
||||
# if Conf.ROLLBAR:
|
||||
# rollbar_conf = deepcopy(Conf.ROLLBAR)
|
||||
# try:
|
||||
# import rollbar
|
||||
# rollbar.init(rollbar_conf.pop('access_token'), environment=rollbar_conf.pop('environment'), **rollbar_conf)
|
||||
# except ImportError:
|
||||
# rollbar = None
|
||||
|
||||
# else:
|
||||
# rollbar = None
|
||||
|
||||
|
||||
|
||||
# get parent pid compatibility
|
||||
|
||||
@@ -55,5 +55,15 @@ setup(
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Topic :: Internet :: WWW/HTTP',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
]
|
||||
],
|
||||
entry_points={
|
||||
'djangoq.errorreporters': [
|
||||
'rollbar = django_q_rollbar.Rollbar',
|
||||
'sentry = django_q_sentry.Sentry',
|
||||
]
|
||||
},
|
||||
extras_require={
|
||||
'rollbar': ["django-q-rollbar>=0.1"],
|
||||
'sentry': ["django-q-sentry>=0.1"],
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user