mirror of
https://github.com/flibusta-apps/telegram_files_cache_server.git
synced 2026-03-03 15:10:48 +01:00
Migrate to ruff
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from fastapi import Security, HTTPException, status
|
||||
from fastapi import HTTPException, Security, status
|
||||
|
||||
from core.auth import default_security
|
||||
from core.config import env_config
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ormar
|
||||
|
||||
from core.db import metadata, database
|
||||
from core.db import database, metadata
|
||||
|
||||
|
||||
class BaseMeta(ormar.ModelMeta):
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import collections
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import random
|
||||
from datetime import timedelta
|
||||
from tempfile import SpooledTemporaryFile
|
||||
from typing import Optional, cast
|
||||
|
||||
from fastapi import UploadFile
|
||||
|
||||
import httpx
|
||||
from arq.connections import ArqRedis
|
||||
from arq.worker import Retry
|
||||
import httpx
|
||||
from fastapi import UploadFile
|
||||
from redis import asyncio as aioredis
|
||||
from redis.exceptions import LockError
|
||||
|
||||
@@ -17,8 +16,7 @@ from app.models import CachedFile
|
||||
from app.services.caption_getter import get_caption
|
||||
from app.services.downloader import download
|
||||
from app.services.files_client import upload_file
|
||||
from app.services.library_client import get_books, get_book, Book
|
||||
|
||||
from app.services.library_client import Book, get_book, get_books
|
||||
|
||||
logger = logging.getLogger("telegram_channel_files_manager")
|
||||
|
||||
@@ -61,7 +59,7 @@ async def check_books(ctx: dict, *args, **kwargs) -> None: # NOSONAR
|
||||
try:
|
||||
books_page = await get_books(1, PAGE_SIZE)
|
||||
except httpx.ConnectError:
|
||||
raise Retry(defer=15)
|
||||
raise Retry(defer=15) # noqa: B904
|
||||
|
||||
for i, page_number in enumerate(range(books_page.total_pages, 0, -1)):
|
||||
await arq_pool.enqueue_job(
|
||||
@@ -143,7 +141,9 @@ async def cache_file_by_book_id(
|
||||
if by_request:
|
||||
return result
|
||||
except LockError:
|
||||
raise Retry(defer=timedelta(minutes=15).seconds * random.random())
|
||||
raise Retry( # noqa: B904
|
||||
defer=timedelta(minutes=15).seconds * random.random()
|
||||
)
|
||||
except Retry as e:
|
||||
if by_request:
|
||||
return None
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
from datetime import date
|
||||
from typing import Generic, TypeVar, Optional
|
||||
from typing import Generic, Optional, TypeVar
|
||||
|
||||
import httpx
|
||||
from pydantic import BaseModel
|
||||
|
||||
from core.config import env_config
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import asyncio
|
||||
import base64
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Request
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from starlette.background import BackgroundTask
|
||||
|
||||
from arq.connections import ArqRedis
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from fastapi.responses import StreamingResponse
|
||||
from starlette.background import BackgroundTask
|
||||
|
||||
from app.depends import check_token
|
||||
from app.models import CachedFile as CachedFileDB
|
||||
@@ -17,7 +15,6 @@ from app.services.downloader import get_filename
|
||||
from app.services.files_client import download_file as download_file_from_cache
|
||||
from app.services.library_client import get_book
|
||||
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/api/v1", tags=["files"], dependencies=[Depends(check_token)]
|
||||
)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import ORJSONResponse
|
||||
|
||||
from prometheus_fastapi_instrumentator import Instrumentator
|
||||
|
||||
from app.views import router, healthcheck_router
|
||||
import core.sentry # noqa: F401
|
||||
from app.views import healthcheck_router, router
|
||||
from core.arq_pool import get_arq_pool
|
||||
from core.db import database
|
||||
from core.redis_client import get_client
|
||||
import core.sentry # noqa: F401
|
||||
|
||||
|
||||
def start_app() -> FastAPI:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from arq.connections import create_pool, RedisSettings, ArqRedis
|
||||
import msgpack
|
||||
from arq.connections import ArqRedis, RedisSettings, create_pool
|
||||
|
||||
from core.config import env_config
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from fastapi.security import APIKeyHeader
|
||||
|
||||
|
||||
default_security = APIKeyHeader(name="Authorization")
|
||||
|
||||
@@ -5,7 +5,6 @@ from sqlalchemy import MetaData
|
||||
|
||||
from core.config import env_config
|
||||
|
||||
|
||||
DATABASE_URL = (
|
||||
f"postgresql://{env_config.POSTGRES_USER}:{quote(env_config.POSTGRES_PASSWORD)}@"
|
||||
f"{env_config.POSTGRES_HOST}:{env_config.POSTGRES_PORT}/{env_config.POSTGRES_DB}"
|
||||
|
||||
@@ -2,7 +2,6 @@ import sentry_sdk
|
||||
|
||||
from core.config import env_config
|
||||
|
||||
|
||||
sentry_sdk.init(
|
||||
env_config.SENTRY_DSN,
|
||||
)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import msgpack
|
||||
|
||||
import core.sentry # noqa: F401
|
||||
from app.services.cache_updater import (
|
||||
check_books,
|
||||
cache_file_by_book_id,
|
||||
check_books,
|
||||
check_books_page,
|
||||
)
|
||||
from core.arq_pool import get_redis_settings, get_arq_pool
|
||||
from core.arq_pool import get_arq_pool, get_redis_settings
|
||||
from core.db import database
|
||||
from core.redis_client import get_client
|
||||
import core.sentry # noqa: F401
|
||||
|
||||
|
||||
async def startup(ctx):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from core.app import start_app
|
||||
|
||||
|
||||
app = start_app()
|
||||
|
||||
Reference in New Issue
Block a user