# Path: mrq/redishelpers.py
# def redis_key(name, *args):
#   prefix = context.get_current_config()["redis_prefix"]
#   if name == "known_subqueues":
#     return "%s:ksq:%s" % (prefix, args[0].root_id)
#   elif name == "queue":
#      return "%s:q:%s" % (prefix, args[0].id)
#   elif name == "started_jobs":
#     return "%s:s:started" % prefix
#   elif name == "paused_queues":
#     return "%s:s:paused" % prefix
#   elif name == "notify":
#      return "%s:notify:%s" % (prefix, args[0].root_id)


from future.builtins import bytes, str, object
from bson import ObjectId
from . import context
from . import job as jobmodule
from .redishelpers import redis_key
from future import standard_library
from itertools import chain
            from .queue_regular import QueueRegular
            from .queue_raw import QueueRaw
import time
import binascii
import sys

    @classmethod
    def all(cls):
        """ List all queues in MongoDB via aggregation, with their queued jobs counts. Might be slow. """

        # Start with raw queues we know exist from the config
        queues = {x: 0 for x in Queue.get_queues_config()}

        stats = list(context.connections.mongodb_jobs.mrq_jobs.aggregate([
            {"$match": {"status": "queued"}},
            {"$group": {"_id": "$queue", "jobs": {"$sum": 1}}}
        ]))

        queues.update({x["_id"]: x["jobs"] for x in stats})

        return queues

    def use_notify(self):
        """ Does this queue use notifications? """
        return bool(self.get_config().get("notify"))

    def notify(self, new_jobs_count):
        """ We just queued new_jobs_count jobs on this queue, wake up the workers if needed """

        if not self.use_notify():
            return

        # Not really useful to send more than 100 notifs (to be configured)
        count = min(new_jobs_count, 100)


# Path: mrq/redishelpers.py
# def redis_key(name, *args):
#   prefix = context.get_current_config()["redis_prefix"]
#   if name == "known_subqueues":
#     return "%s:ksq:%s" % (prefix, args[0].root_id)
#   elif name == "queue":
#      return "%s:q:%s" % (prefix, args[0].id)
#   elif name == "started_jobs":
#     return "%s:s:started" % prefix
#   elif name == "paused_queues":
#     return "%s:s:paused" % prefix
#   elif name == "notify":
#      return "%s:notify:%s" % (prefix, args[0].root_id)


# Path: mrq/queue.py
from future.builtins import bytes, str, object
from bson import ObjectId
from . import context
from . import job as jobmodule
from .redishelpers import redis_key
from future import standard_library
from itertools import chain
            from .queue_regular import QueueRegular
            from .queue_raw import QueueRaw
import time
import binascii
import sys


    @classmethod
    def all(cls):
        """ List all queues in MongoDB via aggregation, with their queued jobs counts. Might be slow. """

        # Start with raw queues we know exist from the config
        queues = {x: 0 for x in Queue.get_queues_config()}

        stats = list(context.connections.mongodb_jobs.mrq_jobs.aggregate([
            {"$match": {"status": "queued"}},
            {"$group": {"_id": "$queue", "jobs": {"$sum": 1}}}
        ]))

        queues.update({x["_id"]: x["jobs"] for x in stats})

        return queues

    def use_notify(self):
        """ Does this queue use notifications? """
        return bool(self.get_config().get("notify"))

    def notify(self, new_jobs_count):
        """ We just queued new_jobs_count jobs on this queue, wake up the workers if needed """

        if not self.use_notify():
            return

        # Not really useful to send more than 100 notifs (to be configured)
        count = min(new_jobs_count, 100)


        notify_key = redis_key("notify", self)