2525import typing
2626import warnings
2727import uuid
28-
28+ import randomname
2929import click
3030import psutil
3131
@@ -252,19 +252,12 @@ def _handle_exception_throw(
252252 else f"An exception was thrown: { _exception_thrown } "
253253 )
254254
255- self .log_event (_event_msg )
256- self .set_status ("terminated" if _is_terminated else "failed" )
257-
258255 # If the dispatcher has already been aborted then this will
259256 # fail so just continue without the event
260257 with contextlib .suppress (RuntimeError ):
261- self .log_event (f" { _exception_thrown } : { value } " )
258+ self .log_event (_event_msg )
262259
263- if not traceback :
264- return
265-
266- with contextlib .suppress (RuntimeError ):
267- self .log_event (f"Traceback: { traceback } " )
260+ self .set_status ("terminated" if _is_terminated else "failed" )
268261
269262 def __exit__ (
270263 self ,
@@ -470,12 +463,13 @@ def _start(self, reconnect: bool = False) -> bool:
470463
471464 logger .debug ("Starting run" )
472465
466+ self ._start_time = time .time ()
467+
473468 if self ._sv_obj and self ._sv_obj .status != "running" :
474469 self ._sv_obj .status = self ._status
470+ self ._sv_obj .started = self ._start_time
475471 self ._sv_obj .commit ()
476472
477- self ._start_time = time .time ()
478-
479473 if self ._pid == 0 :
480474 self ._pid = os .getpid ()
481475
@@ -655,6 +649,8 @@ def init(
655649 if name and not re .match (r"^[a-zA-Z0-9\-\_\s\/\.:]+$" , name ):
656650 self ._error ("specified name is invalid" )
657651 return False
652+ elif not name and self ._user_config .run .mode == "offline" :
653+ name = randomname .get_name ()
658654
659655 self ._name = name
660656
@@ -695,6 +691,7 @@ def init(
695691 self ._sv_obj .metadata = (metadata or {}) | git_info (os .getcwd ()) | environment ()
696692 self ._sv_obj .heartbeat_timeout = timeout
697693 self ._sv_obj .alerts = []
694+ self ._sv_obj .created = time .time ()
698695 self ._sv_obj .notifications = notification
699696
700697 if self ._status == "running" :
@@ -724,7 +721,7 @@ def init(
724721 fg = "green" if self ._term_color else None ,
725722 )
726723 click .secho (
727- f"[simvue] Monitor in the UI at { self ._user_config .server .url } /dashboard/runs/run/{ self ._id } " ,
724+ f"[simvue] Monitor in the UI at { self ._user_config .server .url . rsplit ( '/api' , 1 )[ 0 ] } /dashboard/runs/run/{ self ._id } " ,
728725 bold = self ._term_color ,
729726 fg = "green" if self ._term_color else None ,
730727 )
@@ -1469,7 +1466,7 @@ def set_status(
14691466 ) -> bool :
14701467 """Set run status
14711468
1472- status to assign to this run
1469+ status to assign to this run once finished
14731470
14741471 Parameters
14751472 ----------
@@ -1489,6 +1486,7 @@ def set_status(
14891486
14901487 if self ._sv_obj :
14911488 self ._sv_obj .status = status
1489+ self ._sv_obj .endtime = time .time ()
14921490 self ._sv_obj .commit ()
14931491 return True
14941492
@@ -1641,9 +1639,7 @@ def add_alerts(
16411639 if names and not ids :
16421640 try :
16431641 if alerts := Alert .get (offline = self ._user_config .run .mode == "offline" ):
1644- for alert in alerts :
1645- if alert [1 ].name in names :
1646- ids .append (alert [1 ].id )
1642+ ids += [id for id , alert in alerts if alert .name in names ]
16471643 else :
16481644 self ._error ("No existing alerts" )
16491645 return False
0 commit comments