1313
1414namespace BlitzPHP \Tasks \Commands ;
1515
16+ use BlitzPHP \Tasks \Task ;
1617use BlitzPHP \Tasks \TaskRunner ;
1718
1819/**
@@ -29,7 +30,7 @@ class Run extends TaskCommand
2930 * {@inheritDoc}
3031 */
3132 protected $ options = [
32- '--task ' => 'Run specific task by alias. ' ,
33+ '--task ' => 'Exécuter une tâche spécifique par son alias. ' ,
3334 ];
3435
3536 /**
@@ -50,18 +51,31 @@ public function execute(array $params)
5051 $ this ->newLine ();
5152 }
5253
53- $ this ->task ('Exécution de tâches... ' );
54+ $ this ->task ('Exécution de tâches... ' )-> eol () ;
5455
55- call_user_func (config ('tasks.init ' ), service ('scheduler ' ));
56+ call_user_func (config ('tasks.init ' ), $ scheduler = service ('scheduler ' ));
5657
57- $ runner = new TaskRunner ( );
58+ $ only = $ this -> option ( ' task ' );
5859
59- if ($ task = $ this ->option ('task ' )) {
60- $ runner ->only ([$ task ]);
60+ $ tasks = collect ($ scheduler ->getTasks ())
61+ ->filter (fn (Task $ task ) => $ task ->shouldRun ())
62+ ->filter (fn (Task $ task ) => $ only === null ? true : $ task ->name === $ only );
63+
64+ if ($ tasks ->isEmpty ()) {
65+ $ this ->writer ->error ('Aucune tâche à exécuter. ' );
66+
67+ return EXIT_ERROR ;
68+ }
69+
70+ $ runner = new TaskRunner ($ scheduler );
71+
72+ if ($ only ) {
73+ $ runner ->only ([$ only ]);
6174 }
6275
6376 $ runner ->run ();
6477
78+ $ this ->eol ()->border ();
6579 $ this ->writer ->ok ('Tâches en cours d \'exécution terminées ' );
6680
6781 return EXIT_SUCCESS ;
0 commit comments