Exemplo n.º 1
0
    def _cancel_celery_processes(self,
                                 torrents: "QuerySet[MovieTorrent]") -> None:
        torrents = [torrent.id for torrent in torrents]
        if not torrents:
            return

        if not is_redis_online():
            return

        processes: List[Any] = []
        try:
            nodes: List[str] = get_celery_nodes()
        except Exception:
            return

        inspect: Inspect = app.control.inspect(nodes)
        [processes.extend(process) for process in inspect.active().values()]
        [processes.extend(process) for process in inspect.reserved().values()]
        [processes.extend(process) for process in inspect.scheduled().values()]

        for process in processes:
            if process.get("id"):
                app.control.revoke(process.get("id"))

            if process.get("request") and process.get("request", {}).get("id"):
                app.control.revoke(process.get("request", {}).get("id"))
Exemplo n.º 2
0
    def post(self, request: Request) -> Response:
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        if not is_redis_online():
            raise APIException("RabbitMQ is not running. Cannot process the request.")

        app.control.revoke(serializer.object.process_id)

        return Response({"status": "success"})
Exemplo n.º 3
0
    def get(self, request: Request) -> Response:
        if not is_redis_online():
            raise APIException("Redis is offline.")

        nodes: List[str] = get_celery_nodes()
        logger.info(f"Celery nodes: {nodes}")

        inspect: Inspect = app.control.inspect(nodes)

        return Response(
            {
                "active": self._concatenate(inspect.active()),
                "reserved": self._concatenate(inspect.reserved()),
                "scheduled": self._concatenate(inspect.scheduled()),
            },
            status=status.HTTP_200_OK,
        )
Exemplo n.º 4
0
def background_processes(request: WSGIRequest) -> HttpResponse:
    redis_status: bool = is_redis_online()
    celery: bool = False
    if redis_status and is_celery_running():
        celery = True

    qbittorrent: bool = is_qbittorrent_running()

    if redis_status and celery and qbittorrent and request.GET.get("next"):
        return HttpResponseRedirect(request.GET.get("next"))

    return render(
        request,
        "panel/background_process.html",
        context={
            "qbittorrent": qbittorrent,
            "redis": redis_status,
            "celery": celery,
        },
    )
Exemplo n.º 5
0
def is_background_running() -> bool:
    if not is_qbittorrent_running() or not is_redis_online(
    ) or not is_celery_running():
        return False

    return True