# Path: feedhq/utils.py
# def get_redis_connection():
#     """
#     Helper used for obtain a raw redis client.
#     """
#     from redis_cache.cache import pool
#     client = redis.Redis(**settings.REDIS)
#     client.connection_pool = pool.get_connection_pool(
#         client,
#         parser_class=redis.connection.HiredisParser,
#         connection_pool_class=redis.ConnectionPool,
#         connection_pool_class_kwargs={},
#         **settings.REDIS)
#     return client


import os
from raven import Client
from rq import Connection, Queue, Worker
from structlog import get_logger
from . import SentryCommand
from ....utils import get_redis_connection
def sentry_handler(job, *exc_info):
    extra = {
        'job_id': job.id,
        'func': job.func,
        'args': job.args,
        'kwargs': job.kwargs,
        'description': job.description,
    }
    logger.info("job exception", exc_info=exc_info, **extra)
    if 'SENTRY_DSN' not in os.environ:
        # Don't escalate to other handlers
        return False
    client = Client()
    client.captureException(
        exc_info=exc_info,
        extra=extra,
    )
    return False


class Command(SentryCommand):
    help = "Run a RQ worker on selected queues."

    def add_arguments(self, parser):
        parser.add_argument('queues', nargs='+')
        parser.add_argument('--burst', dest='burst', action='store_true',
                            default=False,
                            help='Run the worker in burst mode')

    def handle_sentry(self, *args, **options):

# Path: feedhq/utils.py
# def get_redis_connection():
#     """
#     Helper used for obtain a raw redis client.
#     """
#     from redis_cache.cache import pool
#     client = redis.Redis(**settings.REDIS)
#     client.connection_pool = pool.get_connection_pool(
#         client,
#         parser_class=redis.connection.HiredisParser,
#         connection_pool_class=redis.ConnectionPool,
#         connection_pool_class_kwargs={},
#         **settings.REDIS)
#     return client


# Path: feedhq/feeds/management/commands/rqworker.py
import os
from raven import Client
from rq import Connection, Queue, Worker
from structlog import get_logger
from . import SentryCommand
from ....utils import get_redis_connection

def sentry_handler(job, *exc_info):
    extra = {
        'job_id': job.id,
        'func': job.func,
        'args': job.args,
        'kwargs': job.kwargs,
        'description': job.description,
    }
    logger.info("job exception", exc_info=exc_info, **extra)
    if 'SENTRY_DSN' not in os.environ:
        # Don't escalate to other handlers
        return False
    client = Client()
    client.captureException(
        exc_info=exc_info,
        extra=extra,
    )
    return False


class Command(SentryCommand):
    help = "Run a RQ worker on selected queues."

    def add_arguments(self, parser):
        parser.add_argument('queues', nargs='+')
        parser.add_argument('--burst', dest='burst', action='store_true',
                            default=False,
                            help='Run the worker in burst mode')

    def handle_sentry(self, *args, **options):

        conn = get_redis_connection()