@@ -16,19 +16,28 @@ async def find_match_else_enqueue(
16
16
if not islocked :
17
17
raise Exception ("Could not acquire lock" )
18
18
19
+ queue = await redis_client .lrange (queue_key , 0 , - 1 )
20
+ _print_queue_state (topic , difficulty , queue , True )
21
+
19
22
# Check if the user is already in the queue
20
- if user_id in await redis_client . lrange ( queue_key , 0 , - 1 ) :
23
+ if user_id in queue :
21
24
await release_lock (redis_client , queue_key )
22
25
return Response (status_code = 304 )
23
26
24
27
# Check if there are no other users in the queue
25
28
if await redis_client .llen (queue_key ) == 0 :
26
29
await redis_client .lpush (queue_key , user_id )
30
+ print (f"QUEUE: Added { user_id } to queue" )
31
+ queue = await redis_client .lrange (queue_key , 0 , - 1 )
32
+ _print_queue_state (topic , difficulty , queue , False )
27
33
await release_lock (redis_client , queue_key )
28
34
return Response (status_code = 202 )
29
35
30
36
# There is a user in the queue
31
37
matched_user = await redis_client .rpop (queue_key )
38
+ print (f"QUEUE: Match found for { user_id } and { matched_user } " )
39
+ queue = await redis_client .lrange (queue_key , 0 , - 1 )
40
+ _print_queue_state (topic , difficulty , queue , False )
32
41
await release_lock (redis_client , queue_key )
33
42
response = MatchModel (
34
43
user1 = matched_user ,
@@ -51,8 +60,14 @@ async def remove_user_from_queue(
51
60
if not islocked :
52
61
raise Exception ("Could not acquire lock" )
53
62
54
- if user_id in await redis_client .lrange (queue_key , 0 , - 1 ):
63
+ queue = await redis_client .lrange (queue_key , 0 , - 1 )
64
+ _print_queue_state (topic , difficulty , queue , True )
65
+
66
+ if user_id in queue :
55
67
await redis_client .lrem (queue_key , 0 , user_id )
68
+ print (f"QUEUE: Removed { user_id } from queue" )
69
+ queue = await redis_client .lrange (queue_key , 0 , - 1 )
70
+ _print_queue_state (topic , difficulty , queue , False )
56
71
57
72
await release_lock (redis_client , queue_key )
58
73
await manager .disconnect_all (user_id , topic , difficulty )
@@ -64,3 +79,9 @@ async def remove_user_from_queue(
64
79
# Builds a queue key based on topic and difficulty
65
80
def _build_queue_key (topic : str , difficulty : str ):
66
81
return f"{ topic } :{ difficulty } "
82
+
83
+ def _print_queue_state (topic , difficulty , queue , before : bool ):
84
+ if before :
85
+ print (f"QUEUE: Before Queue for { (topic , difficulty )} : " , queue )
86
+ else :
87
+ print (f"QUEUE: After Queue for { (topic , difficulty )} : " , queue )
0 commit comments