Buckets:

download
raw
2.44 kB
# SPDX-FileCopyrightText: 2023-present MTS PJSC
# SPDX-License-Identifier: Apache-2.0
from typing import TYPE_CHECKING
from celery import Celery
from fastapi import FastAPI, HTTPException
from fastapi.exceptions import RequestValidationError
from pydantic import ValidationError
from syncmaster import _raw_version as syncmaster_version
from syncmaster.db.factory import create_session_factory
from syncmaster.exceptions import SyncmasterError
from syncmaster.server.api.router import api_router
from syncmaster.server.handler import (
http_exception_handler,
syncmsater_exception_handler,
unknown_exception_handler,
validation_exception_handler,
)
from syncmaster.server.middlewares import apply_middlewares
from syncmaster.server.settings import ServerAppSettings as Settings
from syncmaster.settings.logging import setup_logging
if TYPE_CHECKING:
from syncmaster.server.providers.auth import AuthProvider
__all__ = ["application_factory", "get_application"]
def celery_factory(settings: Settings) -> Celery:
return Celery(
__name__,
broker=str(settings.broker.url),
backend="db+" + settings.database.sync_url,
)
def application_factory(settings: Settings) -> FastAPI:
application = FastAPI(
title="SyncMaster",
version=syncmaster_version,
debug=settings.server.debug,
# will be set up by middlewares
openapi_url=None,
docs_url=None,
redoc_url=None,
)
application.state.settings = settings
application.state.celery = celery_factory(settings)
application.state.session_factory = create_session_factory(settings.database)
application.include_router(api_router)
application.exception_handler(RequestValidationError)(validation_exception_handler)
application.exception_handler(ValidationError)(validation_exception_handler)
application.exception_handler(SyncmasterError)(syncmsater_exception_handler)
application.exception_handler(HTTPException)(http_exception_handler)
application.exception_handler(Exception)(unknown_exception_handler)
auth_class: type[AuthProvider] = settings.auth.provider # type: ignore[assignment]
auth_class.setup(application)
apply_middlewares(application, settings)
return application
def get_application() -> FastAPI:
settings = Settings()
setup_logging(settings.logging)
return application_factory(settings=settings)

Xet Storage Details

Size:
2.44 kB
·
Xet hash:
6caa923f0939b928888652d4a8fb243b67aaee04706801d7d51d3798deaa7bcc

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.