sync-v2 step 4: event-driven account lifecycle (§3)
- Coordinator subscribes to account.state_changed over Redis pub/sub: going live marks the account claimable at once; disabled/deleted/error tears the owning runner down immediately (≤30s) instead of waiting for the lease TTL. - delete_account now publishes account.state_changed:deleted after dropping the account from sync:live, so teardown is event-driven, not just fencing. - AccountRunner gains a verify loop (defense in depth): it periodically confirms the account is still live and flags itself dead if not; the coordinator reaps dead runners and releases their lease. Zombie loops are structurally impossible. - New core event user.active (SPEC §8.3), published on login and on every WS connect; consumed for tier promotion in step 5. - Acceptance: added event-driven teardown test (isolated from fencing/verify). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -82,10 +82,17 @@ async def delete_account(
|
||||
|
||||
# Deregister from sync:live and drop any lease so the owning sync worker
|
||||
# stops the account's runner on its next renewal (refactor §2 fencing).
|
||||
from app.events import get_event_bus
|
||||
from app.redis_client import get_redis
|
||||
from app.sync import leases
|
||||
|
||||
await leases.mark_not_live(get_redis(), account_id)
|
||||
# Sync v2 §3: signal the owning worker to tear the runner down now (≤30s),
|
||||
# rather than waiting for the lease to lapse.
|
||||
await get_event_bus().publish(
|
||||
"account.state_changed",
|
||||
{"user_id": str(user_id), "account_id": str(account_id), "state": "deleted"},
|
||||
)
|
||||
|
||||
# Content-addressed blobs are shared across the user's accounts (dedup): only
|
||||
# remove a blob when no remaining message/attachment references it.
|
||||
|
||||
Reference in New Issue
Block a user