@@ -39,14 +39,16 @@ def __str__(self) -> str:
3939
4040 def _format_status_as_table (self , statuses : Dict [str , QueueStatus ]) -> str :
4141 """
42- Format queue statuses as a string table.
42+ Format queue statuses as a table using tabulate .
4343
4444 Args:
4545 statuses: Dict mapping queue names to QueueStatus
4646
4747 Returns:
4848 Formatted table string
4949 """
50+ from tabulate import tabulate
51+
5052 if not statuses :
5153 return "No queue status data available."
5254
@@ -61,11 +63,11 @@ def _format_status_as_table(self, statuses: Dict[str, QueueStatus]) -> str:
6163 data .append (
6264 {
6365 "Queue" : queue_name ,
64- "Pending" : str ( status .pending ) ,
65- "In Progress" : str ( status .in_progress ) ,
66- "Processed" : str ( status .processed ) ,
67- "Errors" : str ( status .error_count ) ,
68- "Total" : str ( total ) ,
66+ "Pending" : status .pending ,
67+ "In Progress" : status .in_progress ,
68+ "Processed" : status .processed ,
69+ "Errors" : status .error_count ,
70+ "Total" : total ,
6971 }
7072 )
7173 total_pending += status .pending
@@ -78,51 +80,15 @@ def _format_status_as_table(self, statuses: Dict[str, QueueStatus]) -> str:
7880 data .append (
7981 {
8082 "Queue" : "TOTAL" ,
81- "Pending" : str ( total_pending ) ,
82- "In Progress" : str ( total_in_progress ) ,
83- "Processed" : str ( total_processed ) ,
84- "Errors" : str ( total_errors ) ,
85- "Total" : str ( total_total ) ,
83+ "Pending" : total_pending ,
84+ "In Progress" : total_in_progress ,
85+ "Processed" : total_processed ,
86+ "Errors" : total_errors ,
87+ "Total" : total_total ,
8688 }
8789 )
8890
89- # Simple table formatter
90- headers = ["Queue" , "Pending" , "In Progress" , "Processed" , "Errors" , "Total" ]
91- # Default minimum widths similar to previous col_space
92- min_widths = {
93- "Queue" : 20 ,
94- "Pending" : 10 ,
95- "In Progress" : 12 ,
96- "Processed" : 10 ,
97- "Errors" : 8 ,
98- "Total" : 10 ,
99- }
100-
101- col_widths = {h : len (h ) for h in headers }
102-
103- # Calculate max width based on content and min_widths
104- for row in data :
105- for h in headers :
106- content_len = len (str (row .get (h , "" )))
107- col_widths [h ] = max (col_widths [h ], content_len , min_widths .get (h , 0 ))
108-
109- # Add padding
110- for h in headers :
111- col_widths [h ] += 2
112-
113- # Build string
114- lines = []
115-
116- # Header
117- header_line = "" .join (h .ljust (col_widths [h ]) for h in headers )
118- lines .append (header_line )
119-
120- # Rows
121- for row in data :
122- line = "" .join (str (row .get (h , "" )).ljust (col_widths [h ]) for h in headers )
123- lines .append (line )
124-
125- return "\n " .join (lines )
91+ return tabulate (data , headers = "keys" , tablefmt = "pretty" )
12692
12793 def is_healthy (self ) -> bool :
12894 return not self .has_errors ()
0 commit comments