How to use the watchtower.conf function in watchtower

To help you get started, we’ve selected a few watchtower examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github synw / django-watchtower / watchtower / middleware.py View on Github external
# -*- coding: utf-8 -*-

import inspect
import time
import redis
from threading import Thread
from django.db import connection
from watchtower.db import dispatch
from watchtower import serializer, conf as CONF
try:
    from django.utils.deprecation import MiddlewareMixin
except ImportError:
    MiddlewareMixin = object

R = redis.StrictRedis(
    host=CONF.REDIS["host"], port=CONF.REDIS["port"], db=CONF.REDIS["db"])

HITNUM = int(time.time())


class HitsMiddleware(MiddlewareMixin):

    def process_view(self, request, view_func, *args, **kwargs):
        global CONF
        """
        Credits: https://github.com/bitlabstudio/django-influxdb-metrics/blob/master/influxdb_metrics/middleware.py
        """
        if CONF.STOP:
            return
        view = view_func
        if not inspect.isfunction(view_func):
            view = view.__class__