1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of BlitzPHP Tasks. |
7
|
|
|
* |
8
|
|
|
* (c) 2025 Dimitri Sitchet Tomkeu <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view |
11
|
|
|
* the LICENSE file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace BlitzPHP\Tasks\Commands; |
15
|
|
|
|
16
|
|
|
use BlitzPHP\Tasks\Task; |
17
|
|
|
use BlitzPHP\Tasks\TaskRunner; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Exécute les tâches en cours. |
21
|
|
|
*/ |
22
|
|
|
class Run extends TaskCommand |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritDoc} |
26
|
|
|
*/ |
27
|
|
|
protected $name = 'tasks:run'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritDoc} |
31
|
|
|
*/ |
32
|
|
|
protected $options = [ |
33
|
|
|
'--task' => 'Exécuter une tâche spécifique par son alias.', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
*/ |
39
|
|
|
protected $description = 'Exécute des tâches en fonction de la planification, doit être configuré comme une tâche cron pour s\'exécuter toutes les minutes.'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritDoc} |
43
|
|
|
* |
44
|
|
|
* @return int |
45
|
|
|
*/ |
46
|
|
|
public function execute(array $params) |
47
|
|
|
{ |
48
|
|
|
if (parametre('tasks.enabled') === false) { |
49
|
|
|
$this->writer->error('WARNING: L\'exécution de la tâche est actuellement désactivée.', true); |
50
|
|
|
$this->writer->write("Pour réactiver les tâches, exécutez\u{a0}: `tasks:enable`", true); |
51
|
|
|
$this->newLine(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->task('Exécution de tâches...')->eol(); |
55
|
|
|
|
56
|
|
|
call_user_func(config('tasks.init'), $scheduler = service('scheduler')); |
|
|
|
|
57
|
|
|
|
58
|
|
|
$only = $this->option('task'); |
59
|
|
|
|
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]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$runner->run(); |
77
|
|
|
|
78
|
|
|
$this->eol()->border(); |
79
|
|
|
$this->writer->ok('Tâches en cours d\'exécution terminées'); |
80
|
|
|
|
81
|
|
|
return EXIT_SUCCESS; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|