1111CONCURRENT_TASKS_LIMIT_EXCEEDED_COUNTER = Counter (
1212 "posthog_celery_task_concurrency_limit_exceeded" ,
1313 "Number of times a Celery task exceeded the concurrency limit" ,
14- ["task_name" , "limit" ],
14+ ["task_name" , "limit" , "limit_name" ],
1515)
1616
1717# Lua script for atomic check, remove expired if limit hit, and increment with TTL
@@ -44,7 +44,9 @@ class CeleryConcurrencyLimitExceeded(Exception):
4444 pass
4545
4646
47- def limit_concurrency (max_concurrent_tasks : int , key : Optional [Callable ] = None , ttl : int = 60 * 15 ) -> Callable :
47+ def limit_concurrency (
48+ max_concurrent_tasks : int , key : Optional [Callable ] = None , ttl : int = 60 * 15 , limit_name : str = ""
49+ ) -> Callable :
4850 def decorator (task_func ):
4951 @wraps (task_func )
5052 def wrapper (* args , ** kwargs ):
@@ -64,7 +66,9 @@ def wrapper(*args, **kwargs):
6466 redis_client .eval (lua_script , 1 , running_tasks_key , current_time , task_id , max_concurrent_tasks , ttl )
6567 == 0
6668 ):
67- CONCURRENT_TASKS_LIMIT_EXCEEDED_COUNTER .labels (task_name = task_name , limit = max_concurrent_tasks ).inc ()
69+ CONCURRENT_TASKS_LIMIT_EXCEEDED_COUNTER .labels (
70+ task_name = task_name , limit = max_concurrent_tasks , limit_name = limit_name
71+ ).inc ()
6872
6973 raise CeleryConcurrencyLimitExceeded (
7074 f"Exceeded maximum concurrent tasks limit: { max_concurrent_tasks } for key: { dynamic_key } "
0 commit comments