Skip to content

Commit 28c5ff0

Browse files
committed
Improve redis handling
Remove bytes decoding that was moved into connection pool. Moreover, improve logging in case of redis access problems in the routing cache.
1 parent c46c7a5 commit 28c5ff0

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="ywsd",
11-
version="0.14.0",
11+
version="0.14.1",
1212
packages=["ywsd"],
1313
url="https://gitlab.rc5.de/eventphone/ywsd",
1414
license="AGPLv3+",

ywsd/busy_cache.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ async def is_busy(self, extension):
100100

101101
async def busy_status(self):
102102
async with redis.Redis(connection_pool=self._yate.redis_pool) as client:
103-
return {
104-
k.decode("ascii"): int(v)
105-
for k, v in (await client.hgetall("busy_cache")).items()
106-
}
103+
return {k: int(v) for k, v in (await client.hgetall("busy_cache")).items()}
107104

108105
async def flush(self):
109106
async with redis.Redis(connection_pool=self._yate.redis_pool) as client:

ywsd/engine.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,17 @@ def _call_route_handler(self, msg: Message) -> Optional[bool]:
210210

211211
async def _retrieve_from_cache_for(self, msg: Message):
212212
called = "lateroute/" + msg.params.get("called")
213-
result = await self._routing_cache.retrieve(called)
213+
try:
214+
result = await self._routing_cache.retrieve(called)
215+
except Exception as e:
216+
backtrace = traceback.format_exc()
217+
logging.error(
218+
"An error occurred while retrieving stored routing cache for target %s: %s\nBacktrace: %s",
219+
called,
220+
e,
221+
backtrace,
222+
)
223+
raise
214224
if result is None:
215225
# This is an invalid entry, answer the message but with invalid result
216226
msg.result = ""

ywsd/routing_cache.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,28 @@ def __init__(self, yate, settings):
5353
self._redis_pool = yate.redis_pool
5454

5555
async def retrieve(self, target) -> Optional[IntermediateRoutingResult]:
56-
async with redis.Redis(
57-
connection_pool=self._redis_pool, decode_responses=True
58-
) as client:
59-
data = await client.get(target)
56+
async with redis.Redis(connection_pool=self._redis_pool) as client:
57+
try:
58+
data = await client.get(target)
59+
except Exception as e:
60+
logging.error(
61+
"Failure to retrieve cached routing result from redis: %s", e
62+
)
63+
raise
6064
if data is None:
6165
return None
6266
data = json.loads(data)
6367
return IntermediateRoutingResult.deserialize(data)
6468

6569
async def update(self, results: Dict[str, IntermediateRoutingResult]):
66-
async with redis.Redis(
67-
connection_pool=self._redis_pool, decode_responses=True
68-
) as client:
69-
for key, routing_result in results.items():
70-
await client.setex(
71-
key, self._object_lifetime, json.dumps(routing_result.serialize())
72-
)
70+
async with redis.Redis(connection_pool=self._redis_pool) as client:
71+
try:
72+
for key, routing_result in results.items():
73+
await client.setex(
74+
key,
75+
self._object_lifetime,
76+
json.dumps(routing_result.serialize()),
77+
)
78+
except Exception as e:
79+
logging.error("Failure to update cached routing in redis: %s", e)
80+
raise

0 commit comments

Comments
 (0)