Skip to content

Commit

Permalink
feat: pre load schema's utility
Browse files Browse the repository at this point in the history
  • Loading branch information
e-lobo committed Aug 30, 2022
1 parent ea01ae7 commit 7b8b2b7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions frappe_graphql/utils/pre_load_schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def pre_load_schemas():
"""
Can be called in https://docs.gunicorn.org/en/stable/settings.html#pre-fork
to pre-load the all sites schema's on all workers.
"""
from frappe.utils import get_sites
from frappe import init_site, init, connect, get_installed_apps, destroy
with init_site():
sites = get_sites()

for site in sites:
import frappe
frappe.local.initialised = False
init(site=site)
connect(site)
if "frappe_graphql" not in get_installed_apps():
continue
try:
from frappe_graphql import get_schema
get_schema()
except Exception:
print(f"Failed to build schema for site {site}")
finally:
destroy()

0 comments on commit 7b8b2b7

Please sign in to comment.