File tree Expand file tree Collapse file tree 4 files changed +15
-11
lines changed
compute/managed-instances/demo Expand file tree Collapse file tree 4 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -81,12 +81,13 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None:
8181# init_db lazily instantiates a database connection pool. Users of Cloud Run or
8282# App Engine may wish to skip this lazy instantiation and connect as soon
8383# as the function is loaded. This is primarily to help testing.
84- @app .before_first_request
84+ @app .before_request
8585def init_db () -> sqlalchemy .engine .base .Engine :
8686 """Initiates connection to database and its' structure."""
8787 global db
88- db = init_connection_pool ()
89- migrate_db (db )
88+ if db is None :
89+ db = init_connection_pool ()
90+ migrate_db (db )
9091
9192
9293@app .route ("/" , methods = ["GET" ])
Original file line number Diff line number Diff line change @@ -81,12 +81,13 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None:
8181# init_db lazily instantiates a database connection pool. Users of Cloud Run or
8282# App Engine may wish to skip this lazy instantiation and connect as soon
8383# as the function is loaded. This is primarily to help testing.
84- @app .before_first_request
84+ @app .before_request
8585def init_db () -> sqlalchemy .engine .base .Engine :
8686 """Initiates connection to database and its structure."""
8787 global db
88- db = init_connection_pool ()
89- migrate_db (db )
88+ if db is None :
89+ db = init_connection_pool ()
90+ migrate_db (db )
9091
9192
9293@app .route ("/" , methods = ["GET" ])
Original file line number Diff line number Diff line change @@ -73,11 +73,12 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None:
7373# init_db lazily instantiates a database connection pool. Users of Cloud Run or
7474# App Engine may wish to skip this lazy instantiation and connect as soon
7575# as the function is loaded. This is primarily to help testing.
76- @app .before_first_request
76+ @app .before_request
7777def init_db () -> sqlalchemy .engine .base .Engine :
7878 global db
79- db = init_connection_pool ()
80- migrate_db (db )
79+ if db is None :
80+ db = init_connection_pool ()
81+ migrate_db (db )
8182
8283
8384@app .route ("/" , methods = ["GET" ])
Original file line number Diff line number Diff line change 3939_cpu_burner = None
4040
4141
42- @app .before_first_request
42+ @app .before_request
4343def init ():
4444 """Initialize the application."""
4545 global _cpu_burner
46- _cpu_burner = CpuBurner ()
46+ if _cpu_burner is None :
47+ _cpu_burner = CpuBurner ()
4748
4849
4950@app .route ("/" )
You can’t perform that action at this time.
0 commit comments