Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrdall committed May 15, 2017
2 parents 754d6ad + 130914b commit 46455d7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
@@ -1,6 +1,7 @@
=== (ongoing - to be released as 1.4.0) ===

- Added Dockerfile for running tests against a real instance
- Improved util functions

=== 1.3.0 ===

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Expand Up @@ -11,8 +11,8 @@ much better way.
Prerequisites
-------------

This module has celery as a dependency but you don't have to use it, if you
don't want to.
This module has celery support but you don't have to use it, if you don't want
to.

Installation
------------
Expand Down Expand Up @@ -246,7 +246,7 @@ If you want to contribute to this project, please perform the following steps
Runing tests
------------

For running the tests [Docker](https://docs.docker.com/) and
For running the tests [Docker](https://docs.docker.com/) and
[Docker compose](https://www.docker.com/products/docker-compose) is required.

The test setup a Influxdb database for testing against real queries.
Expand Down
3 changes: 2 additions & 1 deletion influxdb_metrics/middleware.py
Expand Up @@ -7,14 +7,15 @@
import urlparse as parse

from django.conf import settings
from django.utils.deprecation import MiddlewareMixin

from tld import get_tld
from tld.exceptions import TldBadUrl, TldDomainNotFound, TldIOError

from .loader import write_points


class InfluxDBRequestMiddleware(object):
class InfluxDBRequestMiddleware(MiddlewareMixin):
"""
Measures request time and sends metric to InfluxDB.
Expand Down
8 changes: 7 additions & 1 deletion influxdb_metrics/tasks.py
@@ -1,7 +1,13 @@
"""Celery tasks for the influxdb_metrics app."""
from __future__ import absolute_import

from celery import shared_task
try:
from celery import shared_task
except ImportError:
def shared_task(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper

from .utils import write_points as write_points_normal

Expand Down
14 changes: 9 additions & 5 deletions influxdb_metrics/utils.py
@@ -1,11 +1,15 @@
"""Utilities for working with influxdb."""
import logging
from threading import Thread

from django.conf import settings

from influxdb import InfluxDBClient


logger = logging.getLogger(__name__)


def get_client():
"""Returns an ``InfluxDBClient`` instance."""
return InfluxDBClient(
Expand Down Expand Up @@ -45,18 +49,18 @@ def write_points(data, force_disable_threading=False):
if force_disable_threading:
use_threading = False
if use_threading is True:
thread = Thread(target=write_points_threaded, args=(client, data, ))
thread = Thread(target=process_points, args=(client, data, ))
thread.start()
else:
client.write_points(data)
process_points(client, data)


def write_points_threaded(client, data): # pragma: no cover
def process_points(client, data): # pragma: no cover
"""Method to be called via threading module."""
try:
client.write_points(data)
except Exception as err:
if getattr(settings, 'INFLUXDB_FAIL_SILENTLY', True):
pass
logger.error(err)
else:
raise err.message
raise err
1 change: 0 additions & 1 deletion requirements.txt
@@ -1,4 +1,3 @@
celery
django
influxdb
tld
Expand Down
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -33,7 +33,6 @@


install_requires = [
'celery>=3.0.0',
'django>=1.6',
'influxdb>=2.9.1',
'tld',
Expand Down

0 comments on commit 46455d7

Please sign in to comment.