MCPcopy
hub / github.com/celery/celery / await_redis_count

Function await_redis_count

t/integration/test_canvas.py:83–107  ·  view source on GitHub ↗

Helper to wait for a specified or well-known redis key to count to a value.

(expected_count, redis_key="redis-count", timeout=TIMEOUT)

Source from the content-addressed store, hash-verified

81
82
83def await_redis_count(expected_count, redis_key="redis-count", timeout=TIMEOUT):
84 """
85 Helper to wait for a specified or well-known redis key to count to a value.
86 """
87 redis_connection = get_redis_connection()
88
89 check_interval = 0.1
90 check_max = int(timeout / check_interval)
91 for i in range(check_max + 1):
92 maybe_count = redis_connection.get(redis_key)
93 # It's either `None` or a base-10 integer
94 if maybe_count is not None:
95 count = int(maybe_count)
96 if count == expected_count:
97 break
98 elif i >= check_max:
99 assert count == expected_count
100 # try again later
101 sleep(check_interval)
102 else:
103 raise TimeoutError(f"{redis_key!r} was never incremented")
104
105 # There should be no more increments - block momentarily
106 sleep(min(1, timeout))
107 assert int(redis_connection.get(redis_key)) == expected_count
108
109
110def compare_group_ids_in_redis(redis_key='redis-group-ids'):

Calls 3

TimeoutErrorClass · 0.90
get_redis_connectionFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected