77from servicelib .rabbitmq import RabbitMQClient
88
99from ..rabbitmq import get_rabbitmq_client
10+ from ._rabbitmq_exclusive_queue_consumers import (
11+ APP_WALLET_SUBSCRIPTION_LOCK_KEY ,
12+ APP_WALLET_SUBSCRIPTIONS_KEY ,
13+ )
1014
1115_logger = logging .getLogger (__name__ )
1216
1317
1418async def subscribe (app : web .Application , wallet_id : WalletID ) -> None :
1519
16- async with app ["wallet_subscription_lock" ]:
17- counter = app ["wallet_subscriptions" ][wallet_id ]
18- app ["wallet_subscriptions" ][wallet_id ] += 1
20+ async with app [APP_WALLET_SUBSCRIPTION_LOCK_KEY ]:
21+ counter = app [APP_WALLET_SUBSCRIPTIONS_KEY ][wallet_id ]
22+ app [APP_WALLET_SUBSCRIPTIONS_KEY ][wallet_id ] += 1
1923
2024 if counter == 0 : # First subscriber
2125 rabbit_client : RabbitMQClient = get_rabbitmq_client (app )
@@ -26,10 +30,10 @@ async def subscribe(app: web.Application, wallet_id: WalletID) -> None:
2630
2731async def unsubscribe (app : web .Application , wallet_id : WalletID ) -> None :
2832
29- async with app ["wallet_subscription_lock" ]:
30- counter = app ["wallet_subscriptions" ].get (wallet_id , 0 )
33+ async with app [APP_WALLET_SUBSCRIPTION_LOCK_KEY ]:
34+ counter = app [APP_WALLET_SUBSCRIPTIONS_KEY ].get (wallet_id , 0 )
3135 if counter > 0 :
32- app ["wallet_subscriptions" ][wallet_id ] -= 1
36+ app [APP_WALLET_SUBSCRIPTIONS_KEY ][wallet_id ] -= 1
3337
3438 if counter == 1 : # Last subscriber
3539 rabbit_client : RabbitMQClient = get_rabbitmq_client (app )
0 commit comments