danswer/backend/shared_configs/contextvars.py
Chris Weaver a5d2f0d9ac
Fix airtable connector w/ mt cloud + move telem logic to match new st… (#3868)
* Fix airtable connector w/ mt cloud + move telem logic to match new standard

* Address Greptile comment

* Small fixes/improvements

* Revert back monitoring frequency

* Small monitoring fix
2025-01-31 16:29:04 -08:00

19 lines
490 B
Python

import contextvars
from shared_configs.configs import POSTGRES_DEFAULT_SCHEMA
# Context variable for the current tenant id
CURRENT_TENANT_ID_CONTEXTVAR = contextvars.ContextVar(
"current_tenant_id", default=POSTGRES_DEFAULT_SCHEMA
)
"""Utils related to contextvars"""
def get_current_tenant_id() -> str:
tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get()
if tenant_id is None:
raise RuntimeError("Tenant ID is not set. This should never happen.")
return tenant_id