Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /nfraxlab_svc-infra /src /svc_infra /data /add.py
| from __future__ import annotations | |
| import inspect | |
| from collections.abc import Callable, Iterable | |
| from fastapi import FastAPI | |
| from svc_infra.cli.cmds.db.sql.alembic_cmds import cmd_setup_and_migrate | |
| def add_data_lifecycle( | |
| app: FastAPI, | |
| *, | |
| auto_migrate: bool = True, | |
| database_url: str | None = None, | |
| discover_packages: list[str] | None = None, | |
| with_payments: bool | None = None, | |
| on_load_fixtures: Callable[[], None] | None = None, | |
| retention_jobs: Iterable[Callable[[], None]] | None = None, | |
| erasure_job: Callable[[str], None] | None = None, | |
| ) -> None: | |
| """ | |
| Wire data lifecycle conveniences: | |
| - auto_migrate: run end-to-end Alembic setup-and-migrate on startup (idempotent). | |
| - on_load_fixtures: optional callback to load reference/fixture data once at startup. | |
| - retention_jobs: optional list of callables to register purge tasks (scheduler integration is external). | |
| - erasure_job: optional callable to trigger a GDPR erasure workflow for a given principal ID. | |
| This helper is intentionally minimal: it coordinates existing building blocks | |
| and offers extension points. Jobs should be scheduled using svc_infra.jobs helpers. | |
| """ | |
| async def _run_lifecycle() -> None: | |
| # Startup | |
| if auto_migrate: | |
| cmd_setup_and_migrate( | |
| database_url=database_url, | |
| overwrite_scaffold=False, | |
| create_db_if_missing=True, | |
| create_followup_revision=True, | |
| initial_message="initial schema", | |
| followup_message="autogen", | |
| discover_packages=discover_packages, | |
| with_payments=with_payments if with_payments is not None else False, | |
| ) | |
| if on_load_fixtures: | |
| res = on_load_fixtures() | |
| if inspect.isawaitable(res): | |
| await res | |
| app.add_event_handler("startup", _run_lifecycle) | |
| # Store optional jobs on app.state for external schedulers to discover/register. | |
| if retention_jobs is not None: | |
| app.state.data_retention_jobs = list(retention_jobs) | |
| if erasure_job is not None: | |
| app.state.data_erasure_job = erasure_job | |
| __all__ = ["add_data_lifecycle"] | |
Xet Storage Details
- Size:
- 2.23 kB
- Xet hash:
- 9ef9d5a752001e8e6f0edc093c00ff3ed886b0b3882e6024d1037ca0689cb712
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.