# 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

    def serialize_job_ids(self, job_ids):
        """ Returns job_ids serialized for storage in Redis """
        if len(job_ids) == 0 or self.use_large_ids:
            return job_ids
        elif isinstance(job_ids[0], ObjectId):
            return [x.binary for x in job_ids]
        else:
            return [bytes.fromhex(str(x)) for x in job_ids]

    def unserialize_job_ids(self, job_ids):
        """ Unserialize job_ids stored in Redis """
        if len(job_ids) == 0 or self.use_large_ids:
            return job_ids
        else:
            return [binascii.hexlify(x.encode('utf-8') if (PY3 and isinstance(x, str)) else x).decode('ascii')
                    for x in job_ids]

    def _get_pausable_id(self):
      """
          Get the queue id (either id or root_id) that should be used to pause/unpause the current queue
          TODO: handle subqueues with more than one level, e.g. "queue/subqueue/"
      """
      queue = self.id
      if self.id.endswith("/"):
          queue = self.root_id
      return queue

    def pause(self):
        """ Adds this queue to the set of paused queues """

# 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


    def serialize_job_ids(self, job_ids):
        """ Returns job_ids serialized for storage in Redis """
        if len(job_ids) == 0 or self.use_large_ids:
            return job_ids
        elif isinstance(job_ids[0], ObjectId):
            return [x.binary for x in job_ids]
        else:
            return [bytes.fromhex(str(x)) for x in job_ids]

    def unserialize_job_ids(self, job_ids):
        """ Unserialize job_ids stored in Redis """
        if len(job_ids) == 0 or self.use_large_ids:
            return job_ids
        else:
            return [binascii.hexlify(x.encode('utf-8') if (PY3 and isinstance(x, str)) else x).decode('ascii')
                    for x in job_ids]

    def _get_pausable_id(self):
      """
          Get the queue id (either id or root_id) that should be used to pause/unpause the current queue
          TODO: handle subqueues with more than one level, e.g. "queue/subqueue/"
      """
      queue = self.id
      if self.id.endswith("/"):
          queue = self.root_id
      return queue

    def pause(self):
        """ Adds this queue to the set of paused queues """

        context.connections.redis.sadd(redis_key("paused_queues"), self._get_pausable_id())