|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhalconExt\Cli\Task; |
|
4
|
|
|
|
|
5
|
|
|
use Ahc\Cli\Input\Command; |
|
6
|
|
|
use Ahc\Cron\Expression; |
|
7
|
|
|
use Phalcon\Cli\Task; |
|
|
|
|
|
|
8
|
|
|
use PhalconExt\Di\ProvidesDi; |
|
9
|
|
|
|
|
10
|
|
|
class ScheduleTask extends Task |
|
11
|
|
|
{ |
|
12
|
|
|
use ProvidesDi; |
|
13
|
|
|
|
|
14
|
|
|
public function onConstruct() |
|
15
|
|
|
{ |
|
16
|
|
|
($console = $this->di('console')) |
|
17
|
|
|
->addTask('schedule:list', 'List scheduled tasks (if any)', false) |
|
18
|
|
|
->tap($console) |
|
19
|
|
|
->addTask('schedule:run', 'Run scheduled tasks that are due', true); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function listAction() |
|
23
|
|
|
{ |
|
24
|
|
|
$io = $this->di('interactor'); |
|
25
|
|
|
|
|
26
|
|
|
if ([] === $tasks = $this->di('console')->scheduled()) { |
|
27
|
|
|
$io->infoBgRed('No scheduled tasks', true); |
|
28
|
|
|
|
|
29
|
|
|
return; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$io->boldGreen('Schedules:', true); |
|
33
|
|
|
|
|
34
|
|
|
$maxLen = \max(\array_map('strlen', \array_keys($tasks))); |
|
35
|
|
|
|
|
36
|
|
|
foreach ($tasks as $taskId => $schedule) { |
|
37
|
|
|
$io->bold(' ' . \str_pad($taskId, $maxLen + 2))->comment($schedule, true); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function runAction() |
|
42
|
|
|
{ |
|
43
|
|
|
$io = $this->di('interactor'); |
|
44
|
|
|
|
|
45
|
|
|
if ([] === $tasks = $this->dueTasks()) { |
|
46
|
|
|
return $io->infoBgRed('No due tasks for now', true); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$params = $this->di(Command::class)->values(); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($tasks as list($task, $action)) { |
|
52
|
|
|
$io->line('--------------------', true) |
|
53
|
|
|
->yellow($task . ':' . $action, true) |
|
54
|
|
|
->line('--------------------', true); |
|
55
|
|
|
|
|
56
|
|
|
$this->di('console')->doHandle(\compact('task', 'action', 'params')); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function dueTasks(): array |
|
61
|
|
|
{ |
|
62
|
|
|
if ([] === $tasks = $this->console->scheduled()) { |
|
63
|
|
|
return []; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$dues = []; |
|
67
|
|
|
$now = \time(); |
|
68
|
|
|
$cron = new Expression; |
|
69
|
|
|
|
|
70
|
|
|
foreach ($tasks as $taskId => $schedule) { |
|
71
|
|
|
if ($cron->isCronDue($schedule, $now)) { |
|
72
|
|
|
$dues[] = \explode(':', $taskId) + ['', 'main']; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $dues; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths