Skip to content

Commit

Permalink
Add verbose option to backend_factory (useful to avoid useless lo…
Browse files Browse the repository at this point in the history
…g output when used in short-lived CLI commands)
  • Loading branch information
touilleMan committed Jan 14, 2025
1 parent 9cc0cf7 commit fd33663
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions server/parsec/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@


@asynccontextmanager
async def backend_factory(config: BackendConfig) -> AsyncGenerator[Backend, None]:
async def backend_factory(config: BackendConfig, verbose: bool) -> AsyncGenerator[Backend, None]:
# Log the server version and the backend configuration
logger.info("Parsec version", version=server_version)
logger.info("Backend configuration", **config.logging_kwargs())
if verbose:
logger.info("Parsec version", version=server_version)
logger.info("Backend configuration", **config.logging_kwargs())

if config.db_config.is_mocked():
components_factory = mocked_components_factory
Expand Down
2 changes: 1 addition & 1 deletion server/parsec/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ async def _run_backend(
retry_policy.new_attempt()

# Run the backend app (and connect to the database)
async with backend_factory(config=app_config) as backend:
async with backend_factory(config=app_config, verbose=True) as backend:
# Connection is successful, reset the retry policy
retry_policy.success()

Expand Down
2 changes: 1 addition & 1 deletion server/parsec/cli/testbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async def testbed_backend_factory(
administration_token="s3cr3t",
organization_spontaneous_bootstrap=True,
)
async with backend_factory(config=config) as backend:
async with backend_factory(config=config, verbose=True) as backend:
yield TestbedBackend(backend=backend)


Expand Down
2 changes: 1 addition & 1 deletion server/tests/common/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def backend(

async def _run_backend():
nonlocal backend
async with backend_factory(config=backend_config) as backend:
async with backend_factory(config=backend_config, verbose=False) as backend:
started.set()
try:
await should_stop.wait()
Expand Down
4 changes: 2 additions & 2 deletions server/tests/test_cross_server_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
@pytest.mark.postgresql
async def test_cross_server_event(backend_config: BackendConfig) -> None:
async with (
backend_factory(config=backend_config) as b1,
backend_factory(config=backend_config) as b2,
backend_factory(config=backend_config, verbose=False) as b1,
backend_factory(config=backend_config, verbose=False) as b2,
):
b2_received_events = Queue()

Expand Down

0 comments on commit fd33663

Please sign in to comment.