# Path: django_lightweight_queue/types.py
# class Logger(Protocol):
#     def log(
#         self,
#         level: int,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def debug(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def info(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def warning(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def error(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def exception(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
# 
# Path: django_lightweight_queue/utils.py
# @lru_cache()
# def get_path(path: str) -> Any:
#     module_name, attr = path.rsplit('.', 1)
# 
#     module = importlib.import_module(module_name)
# 
#     return getattr(module, attr)
# 
# @lru_cache()
# def get_middleware() -> List[Any]:
#     middleware = []
# 
#     for path in app_settings.MIDDLEWARE:
#         try:
#             middleware.append(get_path(path)())
#         except MiddlewareNotUsed:
#             pass
# 
#     return middleware


import sys
import json
import time
import datetime
import warnings
from typing import Any, Dict, Tuple, Callable, Optional, TYPE_CHECKING
from django.db import transaction
from .types import QueueName, WorkerNumber
from .utils import get_path, get_middleware
    from .task import TaskWrapper
                result = task.fn(*self.args, **self.kwargs)

            time_taken = time.time() - start

            for instance in reversed(middleware):
                if hasattr(instance, 'process_result'):
                    instance.process_result(self, result, time_taken)
        except Exception:
            time_taken = time.time() - start

            exc_info = sys.exc_info()

            for instance in reversed(middleware):
                if hasattr(instance, 'process_exception'):
                    try:
                        instance.process_exception(self, time_taken, *exc_info)
                    except Exception:
                        pass

            return False

        return True

    def validate(self) -> None:
        # Ensure these execute without exception so that we cannot enqueue
        # things that are impossible to dequeue.
        self.get_task_instance()
        self.to_json()

    def get_task_instance(self) -> 'TaskWrapper[Callable[..., Any]]':

# Path: django_lightweight_queue/types.py
# class Logger(Protocol):
#     def log(
#         self,
#         level: int,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def debug(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def info(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def warning(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def error(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
#     def exception(
#         self,
#         msg: str,
#         *args: Any,
#         exc_info: _ExcInfoType = ...,
#         stack_info: bool = ...,
#         extra: Optional[Dict[str, Any]] = ...,
#         **kwargs: Any
#     ) -> None:
# 
# Path: django_lightweight_queue/utils.py
# @lru_cache()
# def get_path(path: str) -> Any:
#     module_name, attr = path.rsplit('.', 1)
# 
#     module = importlib.import_module(module_name)
# 
#     return getattr(module, attr)
# 
# @lru_cache()
# def get_middleware() -> List[Any]:
#     middleware = []
# 
#     for path in app_settings.MIDDLEWARE:
#         try:
#             middleware.append(get_path(path)())
#         except MiddlewareNotUsed:
#             pass
# 
#     return middleware


# Path: django_lightweight_queue/job.py
import sys
import json
import time
import datetime
import warnings
from typing import Any, Dict, Tuple, Callable, Optional, TYPE_CHECKING
from django.db import transaction
from .types import QueueName, WorkerNumber
from .utils import get_path, get_middleware
    from .task import TaskWrapper

                result = task.fn(*self.args, **self.kwargs)

            time_taken = time.time() - start

            for instance in reversed(middleware):
                if hasattr(instance, 'process_result'):
                    instance.process_result(self, result, time_taken)
        except Exception:
            time_taken = time.time() - start

            exc_info = sys.exc_info()

            for instance in reversed(middleware):
                if hasattr(instance, 'process_exception'):
                    try:
                        instance.process_exception(self, time_taken, *exc_info)
                    except Exception:
                        pass

            return False

        return True

    def validate(self) -> None:
        # Ensure these execute without exception so that we cannot enqueue
        # things that are impossible to dequeue.
        self.get_task_instance()
        self.to_json()

    def get_task_instance(self) -> 'TaskWrapper[Callable[..., Any]]':

        return get_path(self.path)