@@ -746,60 +746,65 @@ def task_get_status(
746
746
return task_to_status
747
747
748
748
749
+ def _status_code (status : str , code : t .Union [int , str , None ]) -> str :
750
+ if status == "RUNNING" :
751
+ return f"[yellow]RUNNING[/yellow] (pid={ code } )"
752
+ elif status == "FAIL" :
753
+ return f"[red]FAILED[/red] (code={ code } )"
754
+ elif status == "WAITING" :
755
+ return f"[green]WAITING[/green] (on={ code } )"
756
+ elif status == "UNKNOWN" :
757
+ return "[red]UNKNOWN[/red]"
758
+ else :
759
+ return "[green]SUCCESS[/green]"
760
+
761
+
749
762
def task_status_to_table (
750
763
statuses : t .Mapping [str , t .Tuple [str , t .Union [int , str ]]]
751
764
) -> rich .table .Table :
752
765
t = rich .table .Table (title = "Task Status" )
753
766
t .add_column ("Task" )
754
767
t .add_column ("Status" )
755
768
for task , (status , code ) in statuses .items ():
756
- if status == "RUNNING" :
757
- status = f"[yellow]RUNNING[/yellow] (pid={ code } )"
758
- elif status == "FAIL" :
759
- status = f"[red]FAILED[/red] (code={ code } )"
760
- elif status == "WAITING" :
761
- status = f"[green]WAITING[/green] (on={ code } )"
762
- elif status == "UNKNOWN" :
763
- status = "[red]UNKNOWN[/red]"
764
- else :
765
- status = f"[green]SUCCESS[/green] (code={ code } )"
766
- t .add_row (task , status )
769
+ t .add_row (task , _status_code (status , code ))
767
770
return t
768
771
769
772
770
773
def task_join (
771
774
ctx : YoCtx ,
772
775
inst : YoInstance ,
773
- wait_task : t .Optional [str ] = None ,
776
+ wait_tasks : t .Iterable [str ] = () ,
774
777
) -> t .Mapping [str , t .Tuple [str , t .Union [str , int ]]]:
775
778
with Live (console = ctx .con ) as live :
776
- task_previous_status : t .Dict [str , str ] = {}
779
+ task_previous_status : t .Dict [str , t . Tuple [ str , t . Union [ int , str ]] ] = {}
777
780
while True :
778
781
status_dict = task_get_status (ctx , inst )
779
782
live .update (task_status_to_table (status_dict ))
780
783
any_running = False
781
- for task , (status , _ ) in status_dict .items ():
782
- prev_status = task_previous_status .get (task )
783
- task_previous_status [task ] = status
784
+ for task , (status , code ) in status_dict .items ():
785
+ prev_status , prev_code = task_previous_status .get (
786
+ task , (None , None )
787
+ )
788
+ task_previous_status [task ] = status , code
784
789
if not prev_status :
785
- live .console .log (f"{ task } : starting in status { status } " )
786
- elif prev_status != status :
787
790
live .console .log (
788
- f"{ task } : changing status { prev_status } -> { status } "
791
+ f"{ task } : starting in status { _status_code (status , code )} " ,
792
+ highlight = False ,
793
+ )
794
+ elif prev_status != status or prev_code != code :
795
+ live .console .log (
796
+ f"{ task } : changing status { _status_code (prev_status , prev_code )} -> { _status_code (status , code )} " ,
797
+ highlight = False ,
789
798
)
790
799
if status in ("RUNNING" , "WAITING" ):
791
800
any_running = True
792
801
793
802
# If we're waiting for no particular task, then we have to wait
794
803
# until all are completed. Otherwise, we wait until just the
795
- # specific wait_task is completed.
796
- can_terminate = (wait_task is None and not any_running ) or (
797
- wait_task is not None
798
- and status_dict [wait_task ][0 ]
799
- not in (
800
- "RUNNING" ,
801
- "WAITING" ,
802
- )
804
+ # specific wait_tasks are all completed.
805
+ can_terminate = (not wait_tasks and not any_running ) or all (
806
+ (status_dict [wt ][0 ] not in ("RUNNING" , "WAITING" ))
807
+ for wt in wait_tasks
803
808
)
804
809
if can_terminate :
805
810
break
@@ -1717,6 +1722,7 @@ def add_args(self, parser: argparse.ArgumentParser) -> None:
1717
1722
"task" ,
1718
1723
choices = arg_choices (list_tasks ()),
1719
1724
help = "name of the task to execute" ,
1725
+ nargs = "+" ,
1720
1726
)
1721
1727
parser .add_argument (
1722
1728
"-w" ,
@@ -1726,9 +1732,9 @@ def add_args(self, parser: argparse.ArgumentParser) -> None:
1726
1732
)
1727
1733
1728
1734
def run_for_instance (self , inst : YoInstance ) -> None :
1729
- run_all_tasks (self .c , inst , [ self .args .task ] )
1735
+ run_all_tasks (self .c , inst , self .args .task )
1730
1736
if self .args .wait :
1731
- task_join (self .c , inst , wait_task = self .args .task )
1737
+ task_join (self .c , inst , wait_tasks = self .args .task )
1732
1738
send_notification (
1733
1739
self .c ,
1734
1740
f"Task { self .args .task } complete on instance { inst .name } " ,
@@ -1802,7 +1808,7 @@ def add_args(self, parser: argparse.ArgumentParser) -> None:
1802
1808
)
1803
1809
1804
1810
def run_for_instance (self , inst : YoInstance ) -> None :
1805
- task_join (self .c , inst , wait_task = self .args .task )
1811
+ task_join (self .c , inst , wait_tasks = [ self .args .task ] )
1806
1812
send_notification (
1807
1813
self .c , f"Task { self .args .task } complete on instance { inst .name } "
1808
1814
)
0 commit comments