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:
81
81
# init_db lazily instantiates a database connection pool. Users of Cloud Run or
82
82
# App Engine may wish to skip this lazy instantiation and connect as soon
83
83
# as the function is loaded. This is primarily to help testing.
84
- @app .before_first_request
84
+ @app .before_request
85
85
def init_db () -> sqlalchemy .engine .base .Engine :
86
86
"""Initiates connection to database and its' structure."""
87
87
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 )
90
91
91
92
92
93
@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:
81
81
# init_db lazily instantiates a database connection pool. Users of Cloud Run or
82
82
# App Engine may wish to skip this lazy instantiation and connect as soon
83
83
# as the function is loaded. This is primarily to help testing.
84
- @app .before_first_request
84
+ @app .before_request
85
85
def init_db () -> sqlalchemy .engine .base .Engine :
86
86
"""Initiates connection to database and its structure."""
87
87
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 )
90
91
91
92
92
93
@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:
73
73
# init_db lazily instantiates a database connection pool. Users of Cloud Run or
74
74
# App Engine may wish to skip this lazy instantiation and connect as soon
75
75
# as the function is loaded. This is primarily to help testing.
76
- @app .before_first_request
76
+ @app .before_request
77
77
def init_db () -> sqlalchemy .engine .base .Engine :
78
78
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 )
81
82
82
83
83
84
@app .route ("/" , methods = ["GET" ])
Original file line number Diff line number Diff line change 39
39
_cpu_burner = None
40
40
41
41
42
- @app .before_first_request
42
+ @app .before_request
43
43
def init ():
44
44
"""Initialize the application."""
45
45
global _cpu_burner
46
- _cpu_burner = CpuBurner ()
46
+ if _cpu_burner is None :
47
+ _cpu_burner = CpuBurner ()
47
48
48
49
49
50
@app .route ("/" )
You can’t perform that action at this time.
0 commit comments