strangler_router
DEPRECATED (Phase T3, 2026-06-02) — retained for historical reference only.
During the monolith-to-microservices migration the strangler-fig router decided, per channel/guild, whether a message was served by the legacy monolith or routed over the event bus to the new services. The monolith has since been retired and all traffic flows through the microservices, so this module is no longer imported or instantiated by any service.
Do not import or use StranglerRouter in new code; it exists
only to document the migration history. See core.strangler_router for
the equivalent core-package copy.
- class strangler_router.StranglerRouter(redis)[source]
Bases:
objectDeprecated strangler-fig router that chose monolith vs. microservice.
During the monolith-to-microservices migration this resolved, per channel/guild/platform, whether a message was served by the legacy monolith or routed over the event bus to the new services, supporting a percentage-based rollout and a default fallback. Rules live in the
sg:strangler:routesRedis hash and are cached in memory; a pub/sub listener onsg:pubsub:configflushes that cache when operator scripts rewrite the rules, and aCircuitBreakerguards the cache-miss Redis read so a flaky Redis degrades to the safemonolithdefault rather than raising.Retired in Phase T3 once the monolith was confirmed dead: no live service constructs or imports this class anymore, and the only remaining callers are the migration test suite (
tests/core/migration/test_strangler_router.py). Do not use it in new code; seecore.strangler_routerfor the package copy.- __init__(redis)[source]
Initialize the router with a Redis client and an empty route cache.
Sets up the in-memory
_cachedict that holds routing rules pulled from Redis, aCircuitBreaker(failure_threshold=3,reset_timeout=30.0) that guards the cache-miss path against a flaky Redis, an unset_listen_taskhandle for the background invalidation listener, and a_default_routeof"monolith"used as the safe fallback.This stores the passed
redishandle but performs no I/O; the cache is populated lazily on the first_fetch_route()call. As this module is deprecated (Phase T3), no live service constructs this class; the only callers are historical and the test suite.- Parameters:
redis – An async Redis client (e.g.
redis.asyncio.Redis) used forhgetallof the routes hash and for pub/sub subscription to config-change notifications.
- async start()[source]
Launch the background cache-invalidation listener.
Schedules
_listen_for_invalidations()as a fire-and-forgetasynciotask whose handle is stored onself._listen_tasksostop()can cancel it later. Returns immediately without awaiting the listener.This calls
asyncio.create_task(); the spawned task subscribes to thesg:pubsub:configRedis channel. Historically invoked by the owningGatewayServiceduring startup, but that wiring was removed in Phase T3, so no live caller remains (only the test suite exercises it directly).
- async stop()[source]
Cancel the background invalidation listener and await its teardown.
If a listener task was started, requests cancellation and awaits it, swallowing the resulting
asyncio.CancelledErrorso shutdown completes cleanly. A no-op whenstart()was never called.This cancels the task created in
start()(which runs_listen_for_invalidations()). Historically called byGatewayServiceon shutdown; that wiring was removed in Phase T3, so only the test suite calls it now.
- async get_route(channel=None, guild=None, platform=None)[source]
Resolve the routing target for a message, degrading safely on failure.
Public entry point for routing decisions: delegates to
_fetch_route()through the circuit breaker so a struggling Redis trips the breaker instead of blocking, and converts every failure mode into the safeself._default_route("monolith"). A tripped breaker logsstrangler_circuit_open_fallback_monolithand any other exception logsstrangler_route_errorbefore falling back. As the module is deprecated (Phase T3), no live service calls this; only the migration test suite exercises it.- Parameters:
- Returns:
The resolved route — typically
"monolith","microservice", or"shadow"— falling back to the default route on any error.- Return type: