# Path: mrq/exceptions.py
# class RetryInterrupt(_MrqInterrupt):
#     delay = None
#     queue = None
#     retry_count = 0
# 
#     def _get_exception_name(self):
#         return "%s #%s: %s seconds, %s queue" % (
#             self.__class__.__name__, self.retry_count, self.delay, self.queue
#         )
# 
# class MaxRetriesInterrupt(_MrqInterrupt):
#     pass
# 
# class AbortInterrupt(_MrqInterrupt):
#     pass
# 
# class MaxConcurrencyInterrupt(_MrqInterrupt):
#     pass
# 
# Path: mrq/utils.py
# @memoize_single_argument
# def load_class_by_path(taskpath):
#     """ Given a taskpath, returns the main task class. """
# 
#     return getattr(
#         importlib.import_module(
#             re.sub(
#                 r"\.[^.]+$",
#                 "",
#                 taskpath)),
#         re.sub(
#             r"^.*\.",
#             "",
#             taskpath))
# 
# def group_iter(iterator, n=2):
#     """ Given an iterator, it returns sub-lists made of n items.
#     (except the last that can have len < n)
# 
#     """
# 
#     # Use slices instead of an iterator when we have a flat list
#     if isinstance(iterator, list):
# 
#         length = len(iterator)
#         for i in range(int(math.ceil(old_div(float(length), n)))):
#             yield iterator[i * n: (i + 1) * n]
# 
#     else:
#         accumulator = []
#         for item in iterator:
#             accumulator.append(item)
#             if len(accumulator) == n:
#                 yield accumulator
#                 accumulator = []
# 
#         # Yield what's left
#         if len(accumulator) != 0:
#             yield accumulator


from future import standard_library
from future.builtins import str, object
from bson import ObjectId
from redis.exceptions import LockError
from .exceptions import RetryInterrupt, MaxRetriesInterrupt, AbortInterrupt, MaxConcurrencyInterrupt
from .utils import load_class_by_path, group_iter
from collections import defaultdict
from . import context
    from .queue import Queue
    from .queue import Queue
import datetime
import time
import gevent
import objgraph
import random
import gc
import traceback
import sys
import urllib.parse
import re
import linecache
import fnmatch
import encodings
import copyreg

    progress = 0

    _memory_stop = 0
    _memory_start = 0

    _current_io = None

    # Has this job been inserted in MongoDB yet?
    stored = None

    # List of statuses that don't trigger a storage of this task in MongoDB on raw queues.
    # In task config, use ("started", "success") to avoid storing successful raw tasks at all
    statuses_no_storage = None

    def __init__(self, job_id, queue=None, start=False, fetch=False):
        self.worker = context.get_current_worker()
        self.queue = queue
        self.datestarted = None

        self.collection = context.connections.mongodb_jobs.mrq_jobs

        if job_id is None:
            self.id = None
        else:
            if isinstance(job_id, bytes):
                self.id = ObjectId(job_id.decode('utf-8'))
            else:
                self.id = ObjectId(job_id)


# Path: mrq/exceptions.py
# class RetryInterrupt(_MrqInterrupt):
#     delay = None
#     queue = None
#     retry_count = 0
# 
#     def _get_exception_name(self):
#         return "%s #%s: %s seconds, %s queue" % (
#             self.__class__.__name__, self.retry_count, self.delay, self.queue
#         )
# 
# class MaxRetriesInterrupt(_MrqInterrupt):
#     pass
# 
# class AbortInterrupt(_MrqInterrupt):
#     pass
# 
# class MaxConcurrencyInterrupt(_MrqInterrupt):
#     pass
# 
# Path: mrq/utils.py
# @memoize_single_argument
# def load_class_by_path(taskpath):
#     """ Given a taskpath, returns the main task class. """
# 
#     return getattr(
#         importlib.import_module(
#             re.sub(
#                 r"\.[^.]+$",
#                 "",
#                 taskpath)),
#         re.sub(
#             r"^.*\.",
#             "",
#             taskpath))
# 
# def group_iter(iterator, n=2):
#     """ Given an iterator, it returns sub-lists made of n items.
#     (except the last that can have len < n)
# 
#     """
# 
#     # Use slices instead of an iterator when we have a flat list
#     if isinstance(iterator, list):
# 
#         length = len(iterator)
#         for i in range(int(math.ceil(old_div(float(length), n)))):
#             yield iterator[i * n: (i + 1) * n]
# 
#     else:
#         accumulator = []
#         for item in iterator:
#             accumulator.append(item)
#             if len(accumulator) == n:
#                 yield accumulator
#                 accumulator = []
# 
#         # Yield what's left
#         if len(accumulator) != 0:
#             yield accumulator


# Path: mrq/job.py
from future import standard_library
from future.builtins import str, object
from bson import ObjectId
from redis.exceptions import LockError
from .exceptions import RetryInterrupt, MaxRetriesInterrupt, AbortInterrupt, MaxConcurrencyInterrupt
from .utils import load_class_by_path, group_iter
from collections import defaultdict
from . import context
    from .queue import Queue
    from .queue import Queue
import datetime
import time
import gevent
import objgraph
import random
import gc
import traceback
import sys
import urllib.parse
import re
import linecache
import fnmatch
import encodings
import copyreg


    progress = 0

    _memory_stop = 0
    _memory_start = 0

    _current_io = None

    # Has this job been inserted in MongoDB yet?
    stored = None

    # List of statuses that don't trigger a storage of this task in MongoDB on raw queues.
    # In task config, use ("started", "success") to avoid storing successful raw tasks at all
    statuses_no_storage = None

    def __init__(self, job_id, queue=None, start=False, fetch=False):
        self.worker = context.get_current_worker()
        self.queue = queue
        self.datestarted = None

        self.collection = context.connections.mongodb_jobs.mrq_jobs

        if job_id is None:
            self.id = None
        else:
            if isinstance(job_id, bytes):
                self.id = ObjectId(job_id.decode('utf-8'))
            else:
                self.id = ObjectId(job_id)


        self.data = None