|
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\CronExpression; |
|
17
|
|
|
use BlitzPHP\Tasks\Scheduler; |
|
18
|
|
|
use BlitzPHP\Utilities\Date; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Répertorie les tâches actuellement planifiées. |
|
22
|
|
|
*/ |
|
23
|
|
|
class Lister extends TaskCommand |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritDoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $name = 'tasks:list'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritDoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $description = 'Répertorie les tâches actuellement configurées pour être exécutées.'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritDoc} |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
public function execute(array $params) |
|
41
|
|
|
{ |
|
42
|
|
|
helper('preference'); |
|
43
|
|
|
|
|
44
|
|
|
if (parametre('tasks.enabled') === false) { |
|
45
|
|
|
$this->writer->error('WARNING: L\'exécution de la tâche est actuellement désactivée.', true); |
|
46
|
|
|
$this->writer->write("Pour réactiver les tâches, exécutez\u{a0}: `tasks:enable`", true); |
|
47
|
|
|
$this->newLine(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** @var Scheduler */ |
|
51
|
|
|
$scheduler = service('scheduler'); |
|
52
|
|
|
|
|
53
|
|
|
call_user_func(config('tasks.init'), $scheduler); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
$tasks = []; |
|
56
|
|
|
|
|
57
|
|
|
foreach ($scheduler->getTasks() as $task) { |
|
58
|
|
|
/** @var CronExpression */ |
|
59
|
|
|
$cron = service('cronExpression'); |
|
60
|
|
|
|
|
61
|
|
|
$nextRun = $cron->nextRun($task->getExpression()); |
|
62
|
|
|
$lastRun = $task->lastRun(); |
|
63
|
|
|
|
|
64
|
|
|
$tasks[] = [ |
|
65
|
|
|
'Nom' => $task->name ?: $task->getAction(), |
|
66
|
|
|
'Type' => $task->getType(), |
|
67
|
|
|
'Schedule' => $task->getExpression(), |
|
68
|
|
|
'Derniere exécution' => $lastRun instanceof Date ? $lastRun->toDateTimeString() : $lastRun, |
|
69
|
|
|
'Prochaine exécution' => $nextRun, |
|
70
|
|
|
// 'runs_in' => $nextRun->getDate(), |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
usort($tasks, static fn ($a, $b) => ($a['Prochaine exécution'] < $b['Prochaine exécution']) ? -1 : 1); |
|
75
|
|
|
|
|
76
|
|
|
$this->table($tasks); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|