Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Move saas-related initialization to a startup hook.
Browse files Browse the repository at this point in the history
Previously, the saas-related initialization was not taking effect for the general
webapp runtime - the saas registry would need to be reloaded from disk on the first
API invocation, which added unneeded overhead to that first API call.
With this change, the registry loading from disk is done on server initialization
and is not needed again.
  • Loading branch information
Adam Sachs authored and Adam Sachs committed Oct 3, 2022
1 parent a53f6a4 commit 2ad4a2b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/fidesops/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ async def dispatch_log_request(request: Request, call_next: Callable) -> Respons
raise


@app.on_event("startup")
async def load_saas_registry():
"""
Load the SaaS registry on a startup hook to get the registry initialized
within the app's runtime
"""
if config.database.enabled:
logger.info("Validating SaaS connector templates...")
registry = load_registry(registry_file)
db = get_api_session()
update_saas_configs(registry, db)
db.close()


async def prepare_and_log_request(
endpoint: str,
hostname: Optional[str],
Expand Down Expand Up @@ -237,16 +251,10 @@ def start_webserver() -> None:
)
config.log_all_config_values()

logger.info("Validating SaaS connector templates...")
registry = load_registry(registry_file)

if config.database.enabled:
logger.info("Running any pending DB migrations...")
try:
init_db(config.database.sqlalchemy_database_uri)
db = get_api_session()
update_saas_configs(registry, db)
db.close()
except Exception as error: # pylint: disable=broad-except
logger.error("Connection to database failed: %s", Pii(str(error)))
return
Expand Down

0 comments on commit 2ad4a2b

Please sign in to comment.