@@ -61,18 +61,7 @@ async def _handle_lifespan(scope, receive, send):
61
61
message = await receive ()
62
62
if message ["type" ] == "lifespan.startup" :
63
63
try :
64
- config_file = os .environ .get ("NOT_MY_BOARD_HUB_CONFIG" )
65
- if not config_file :
66
- config_file = "/etc/not-my-board/hub.toml"
67
- config_file = pathlib .Path (config_file )
68
-
69
- if config_file .exists ():
70
- config = util .toml_loads (config_file .read_text ())
71
- else :
72
- config = {}
73
-
74
- hub = Hub (config , http .Client ())
75
- await hub .startup ()
64
+ hub = await _on_startup ()
76
65
scope ["state" ]["hub" ] = hub
77
66
except Exception as err :
78
67
await send ({"type" : "lifespan.startup.failed" , "message" : str (err )})
@@ -90,6 +79,24 @@ async def _handle_lifespan(scope, receive, send):
90
79
logger .warning ("Unknown lifespan message %s" , message ["type" ])
91
80
92
81
82
+ async def _on_startup ():
83
+ config_file = os .environ .get ("NOT_MY_BOARD_HUB_CONFIG" )
84
+ if not config_file :
85
+ config_file = "/etc/not-my-board/hub.toml"
86
+ config_file = pathlib .Path (config_file )
87
+
88
+ if config_file .exists ():
89
+ config = util .toml_loads (config_file .read_text ())
90
+ else :
91
+ logger .warning ('Config file "%s" not found' , config_file )
92
+ config = {}
93
+
94
+ hub = Hub (config , http .Client ())
95
+ await hub .startup ()
96
+
97
+ return hub
98
+
99
+
93
100
@asgineer .to_asgi
94
101
async def _handle_request (request ):
95
102
hub = request .scope ["state" ]["hub" ]
0 commit comments