@@ -45,6 +45,40 @@ class LoggingEventEmitter(EventEmitter):
4545 Uses Rich for colorized, styled console output with icons and visual hierarchy.
4646 """
4747
48+ def _format_duration (self , duration_ms : int | None ) -> str :
49+ """Format duration with color-coded performance indicators."""
50+ if duration_ms is None :
51+ return ""
52+
53+ # Convert to seconds for readability
54+ duration_s = duration_ms / 1000.0
55+
56+ # Color-code based on performance
57+ if duration_s < 1.0 :
58+ color = "green"
59+ icon = "⚡"
60+ elif duration_s < 5.0 :
61+ color = "cyan"
62+ icon = "✨"
63+ elif duration_s < 30.0 :
64+ color = "yellow"
65+ icon = "⏱️"
66+ else :
67+ color = "red"
68+ icon = "🐌"
69+
70+ # Format with appropriate precision
71+ if duration_s < 1.0 :
72+ duration_str = f"{ duration_ms } ms"
73+ elif duration_s < 60.0 :
74+ duration_str = f"{ duration_s :.2f} s"
75+ else :
76+ minutes = int (duration_s // 60 )
77+ seconds = duration_s % 60
78+ duration_str = f"{ minutes } m { seconds :.1f} s"
79+
80+ return f"{ icon } [{ color } ]{ duration_str } [/{ color } ]"
81+
4882 def _format_task_event (self , event : TaskEvent ) -> str :
4983 """Format a task event with colors and icons."""
5084 # Event type to emoji/icon mapping
@@ -53,18 +87,37 @@ def _format_task_event(self, event: TaskEvent) -> str:
5387 "task_completed" : "✅" ,
5488 "task_failed" : "❌" ,
5589 "task_retrying" : "🔄" ,
90+ "task_reenqueued" : "📤" ,
91+ "task_enqueued" : "📥" ,
92+ "task_cancelled" : "🚫" ,
5693 }
5794
5895 icon = event_icons .get (event .event_type .value , "📋" )
5996 event_name = event .event_type .value .replace ("_" , " " ).title ()
6097
61- return (
98+ # Base message with event type and task info
99+ base_msg = (
62100 f"{ icon } [bold cyan]{ event_name } [/bold cyan] "
63101 f"[dim]task=[/dim][yellow]{ event .task_id [:8 ]} [/yellow] "
64- f"[dim]queue =[/dim][magenta]{ event .queue } [/magenta] "
65- f"[dim]worker =[/dim][blue ]{ event .worker_id } [/blue ]"
102+ f"[dim]name =[/dim][bold magenta]{ event .task_name } [/bold magenta] "
103+ f"[dim]queue =[/dim][magenta ]{ event .queue } [/magenta ]"
66104 )
67105
106+ # Add attempt info if > 1
107+ if event .attempt > 1 :
108+ base_msg += f" [dim]attempt=[/dim][orange1]{ event .attempt } [/orange1]"
109+
110+ # Add duration for completed/failed tasks
111+ if event .duration_ms is not None :
112+ duration_str = self ._format_duration (event .duration_ms )
113+ base_msg += f" [dim]duration=[/dim]{ duration_str } "
114+
115+ # Add error info for failed tasks
116+ if event .error and event .event_type .value == "task_failed" :
117+ base_msg += f"\n [dim]└─[/dim] [red]Error:[/red] { event .error } "
118+
119+ return base_msg
120+
68121 def _format_worker_event (self , event : WorkerEvent ) -> str :
69122 """Format a worker event with colors and icons."""
70123 # Event type to emoji/icon mapping
@@ -77,8 +130,36 @@ def _format_worker_event(self, event: WorkerEvent) -> str:
77130 icon = event_icons .get (event .event_type .value , "⚙️" )
78131 event_name = event .event_type .value .replace ("_" , " " ).title ()
79132
133+ # Special formatting for worker_online - make it stand out
134+ if event .event_type .value == "worker_online" :
135+ # Create a simple but elegant startup message
136+ queues_str = ", " .join (event .queues )
137+ return (
138+ f"{ icon } [bold green]{ event_name } [/bold green] "
139+ f"[dim]worker=[/dim][bold blue]{ event .worker_id } [/bold blue] "
140+ f"[dim]queues=[/dim][cyan]\\ [{ queues_str } ][/cyan] "
141+ f"[dim]hostname=[/dim][dim]{ event .hostname } [/dim]"
142+ )
143+
144+ # Special formatting for worker_offline
145+ if event .event_type .value == "worker_offline" :
146+ uptime_str = ""
147+ if event .uptime_seconds :
148+ hours = event .uptime_seconds // 3600
149+ minutes = (event .uptime_seconds % 3600 ) // 60
150+ seconds = event .uptime_seconds % 60
151+ uptime_str = f" [dim]uptime=[/dim][cyan]{ hours } h { minutes } m { seconds } s[/cyan]"
152+
153+ return (
154+ f"{ icon } [bold red]{ event_name } [/bold red] "
155+ f"[dim]worker=[/dim][blue]{ event .worker_id } [/blue] "
156+ f"[dim]processed=[/dim][green]{ event .processed } [/green]"
157+ f"{ uptime_str } "
158+ )
159+
160+ # Standard heartbeat formatting
80161 return (
81- f"{ icon } [bold green ]{ event_name } [/bold green ] "
162+ f"{ icon } [dim ]{ event_name } [/dim ] "
82163 f"[dim]worker=[/dim][blue]{ event .worker_id } [/blue] "
83164 f"[dim]active=[/dim][cyan]{ event .active } [/cyan] "
84165 f"[dim]processed=[/dim][green]{ event .processed } [/green]"
0 commit comments