Coverage for /usr/local/lib/python3.12/site-packages/prefect/server/utilities/messaging/_consumer_names.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 11:21 +0000

1import os 1a

2import socket 1a

3import uuid 1a

4 

5 

6def generate_unique_consumer_name(group_name: str) -> str: 1a

7 """ 

8 Generates a unique consumer name for a given group. 

9 

10 The name is composed of the group name, hostname, process ID, and a short UUID 

11 to ensure uniqueness across different machines and processes. 

12 

13 Args: 

14 group_name: The logical group name for the consumer. 

15 

16 Returns: 

17 A unique string to be used as the consumer name. 

18 """ 

19 hostname = socket.gethostname() 1b

20 pid = os.getpid() 1b

21 short_uuid = uuid.uuid4().hex[:8] 1b

22 return f"{group_name}-{hostname}-{pid}-{short_uuid}" 1b