Private
Public Access
Splits the WebSocket layer into three pieces so one app instance and many
behave identically: ConnectionManager stays a purely local socket registry;
RoomBroadcaster publishes chat messages to a per-room Redis channel and
every instance (including the publisher) forwards received messages to its
own local sockets via a single psubscribe("room:*") listener started in
main.py's lifespan; Presence is a Redis-backed refcounted hash per room
tracking who's connected across all instances.
Presence replaces the old process-local connected_user_ids check that
Phase 4's offline-push logic used -- without it, a user connected on a
different instance would look offline and get a redundant push. Fixing
this was scoped in beyond the issue's literal ask (message fan-out only)
since it's a real correctness gap in a phase specifically about running
more than one instance; a known limitation (no heartbeat/TTL, so a hard
crash leaks a presence increment) is documented in the README instead of
solved here.
New tests/test_broadcast.py spins up two independent app instances sharing
one Postgres + Redis to prove delivery and presence both actually cross
the Redis boundary, not just work in-process. Manually verified the same
thing against two real uvicorn processes on different ports.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
40 lines
772 B
TOML
40 lines
772 B
TOML
[project]
|
|
name = "chatapp"
|
|
version = "0.1.0"
|
|
description = "KeepItTalking chat service backend"
|
|
requires-python = ">=3.11"
|
|
dependencies = [
|
|
"fastapi>=0.115",
|
|
"uvicorn[standard]>=0.32",
|
|
"sqlalchemy>=2.0.36",
|
|
"asyncpg>=0.30",
|
|
"alembic>=1.14",
|
|
"pydantic>=2.9",
|
|
"pydantic[email]>=2.9",
|
|
"pydantic-settings>=2.6",
|
|
"argon2-cffi>=23.1",
|
|
"itsdangerous>=2.2",
|
|
"pywebpush>=2.0",
|
|
"redis>=5.0",
|
|
]
|
|
|
|
[project.scripts]
|
|
chatapp-create-user = "app.cli:main"
|
|
|
|
[project.optional-dependencies]
|
|
dev = [
|
|
"pytest>=8",
|
|
"pytest-asyncio>=0.24",
|
|
"httpx>=0.27",
|
|
]
|
|
|
|
[build-system]
|
|
requires = ["hatchling"]
|
|
build-backend = "hatchling.build"
|
|
|
|
[tool.hatch.build.targets.wheel]
|
|
packages = ["app"]
|
|
|
|
[tool.pytest.ini_options]
|
|
asyncio_mode = "auto"
|