mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-05 06:38:12 +08:00
Merge pull request #131 from Koed00/development
Adds Rollbar support for exceptions
This commit is contained in:
+6
-2
@@ -29,7 +29,7 @@ from django import db
|
|||||||
import signing
|
import signing
|
||||||
import tasks
|
import tasks
|
||||||
|
|
||||||
from django_q.conf import Conf, logger, psutil, get_ppid
|
from django_q.conf import Conf, logger, psutil, get_ppid, rollbar
|
||||||
from django_q.models import Task, Success, Schedule
|
from django_q.models import Task, Success, Schedule
|
||||||
from django_q.status import Stat, Status
|
from django_q.status import Stat, Status
|
||||||
from django_q.brokers import get_broker
|
from django_q.brokers import get_broker
|
||||||
@@ -363,6 +363,8 @@ def worker(task_queue, result_queue, timer, timeout=Conf.TIMEOUT):
|
|||||||
f = getattr(m, func)
|
f = getattr(m, func)
|
||||||
except (ValueError, ImportError, AttributeError) as e:
|
except (ValueError, ImportError, AttributeError) as e:
|
||||||
result = (e, False)
|
result = (e, False)
|
||||||
|
if rollbar:
|
||||||
|
rollbar.report_exc_info()
|
||||||
# We're still going
|
# We're still going
|
||||||
if not result:
|
if not result:
|
||||||
db.close_old_connections()
|
db.close_old_connections()
|
||||||
@@ -372,7 +374,9 @@ def worker(task_queue, result_queue, timer, timeout=Conf.TIMEOUT):
|
|||||||
res = f(*task['args'], **task['kwargs'])
|
res = f(*task['args'], **task['kwargs'])
|
||||||
result = (res, True)
|
result = (res, True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result = (e, False)
|
result = ('{}'.format(e), False)
|
||||||
|
if rollbar:
|
||||||
|
rollbar.report_exc_info()
|
||||||
# Process result
|
# Process result
|
||||||
task['result'] = result[0]
|
task['result'] = result[0]
|
||||||
task['success'] = result[1]
|
task['success'] = result[1]
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ class Conf(object):
|
|||||||
# The redis stats key
|
# The redis stats key
|
||||||
Q_STAT = 'django_q:{}:cluster'.format(PREFIX)
|
Q_STAT = 'django_q:{}:cluster'.format(PREFIX)
|
||||||
|
|
||||||
|
# Optional Rollbar key
|
||||||
|
ROLLBAR = conf.get('rollbar', {})
|
||||||
|
|
||||||
# OSX doesn't implement qsize because of missing sem_getvalue()
|
# OSX doesn't implement qsize because of missing sem_getvalue()
|
||||||
try:
|
try:
|
||||||
QSIZE = Queue().qsize() == 0
|
QSIZE = Queue().qsize() == 0
|
||||||
@@ -160,6 +163,21 @@ if not logger.handlers:
|
|||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
# rollbar
|
||||||
|
if Conf.ROLLBAR:
|
||||||
|
rollbar_conf = 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
|
# get parent pid compatibility
|
||||||
def get_ppid():
|
def get_ppid():
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ django-redis
|
|||||||
iron-mq
|
iron-mq
|
||||||
boto3
|
boto3
|
||||||
pymongo
|
pymongo
|
||||||
|
rollbar
|
||||||
|
|||||||
+3
-2
@@ -20,6 +20,7 @@ psutil==3.3.0
|
|||||||
pymongo==3.2
|
pymongo==3.2
|
||||||
python-dateutil==2.4.2 # via arrow, botocore, iron-core
|
python-dateutil==2.4.2 # via arrow, botocore, iron-core
|
||||||
redis==2.10.5
|
redis==2.10.5
|
||||||
requests==2.9.1 # via iron-core
|
requests==2.9.1 # via iron-core, rollbar
|
||||||
six==1.10.0 # via blessed, python-dateutil
|
rollbar==0.11.1
|
||||||
|
six==1.10.0 # via blessed, python-dateutil, rollbar
|
||||||
wcwidth==0.1.5 # via blessed
|
wcwidth==0.1.5 # via blessed
|
||||||
|
|||||||
Reference in New Issue
Block a user