Skip to content

Commit 0e9538f

Browse files
committed
change: Decouple service autostart from bootstrapping.
1 parent 95a31b4 commit 0e9538f

4 files changed

Lines changed: 7 additions & 10 deletions

File tree

bbblb/cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async def main(ctx, obj, config_file, config, verbose):
163163

164164
config_.populate()
165165
config_.set(WORKER=False)
166-
ctx.obj = await bootstrap(config_, autostart=False, logging=False)
166+
ctx.obj = await bootstrap(config_, logging=False)
167167

168168

169169
# Auto-load all modules in the bbblb.cli package to load all commands.

bbblb/services/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,7 @@ def configure_logging(config: BBBLBConfig):
285285
)
286286

287287

288-
async def bootstrap(
289-
config: BBBLBConfig, autostart=True, logging=True
290-
) -> ServiceRegistry:
288+
async def bootstrap(config: BBBLBConfig, logging=True) -> ServiceRegistry:
291289
import bbblb.services.poller
292290
import bbblb.services.recording
293291
import bbblb.services.analytics
@@ -317,9 +315,6 @@ def watch_debug_level(name, old, new):
317315
ctx.register(bbblb.services.analytics.AnalyticsHandler)
318316
ctx.register(bbblb.services.tenants.TenantCache)
319317

320-
if autostart:
321-
await ctx.start_all()
322-
323318
LOG.debug("Bootstrapping completed!")
324319

325320
return ctx

bbblb/web/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def services(self) -> ServiceRegistry:
3939

4040
@cached_property
4141
def config(self) -> BBBLBConfig:
42-
return cast(BBBLBConfig, self.request.app.state.config)
42+
return self.services.get(BBBLBConfig)
4343

4444
@cached_property
4545
def bbb(self) -> BBBHelper:
@@ -135,8 +135,10 @@ def make_app(config: BBBLBConfig | None = None, autostart=True):
135135

136136
@asynccontextmanager
137137
async def lifespan(app: Starlette):
138-
services = await bbblb.services.bootstrap(config, autostart=autostart)
138+
services = await bbblb.services.bootstrap(config)
139139
async with services:
140+
if autostart:
141+
await services.start_all()
140142
app.state.config = config
141143
app.state.services = services
142144
yield

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def config(db_url, tmp_path):
5151

5252
@pytest_asyncio.fixture(scope="function")
5353
async def services(config: bbblb.settings.BBBLBConfig):
54-
services = await bbblb.services.bootstrap(config, autostart=False)
54+
services = await bbblb.services.bootstrap(config)
5555
async with services:
5656
yield services
5757

0 commit comments

Comments
 (0)