Conditions | 7 |
Paths | 14 |
Total Lines | 35 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 56 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
37 | public function execute(array $params) |
||
38 | { |
||
39 | $this->info('Exéctutions des tâches programmées.'); |
||
40 | |||
41 | [$lastExecutionStartedAt, $executions] = [Date::now()->subMinutes(10), []]; |
||
42 | |||
43 | $command = sprintf( |
||
44 | '%s %s %s', |
||
45 | escapeshellarg(PHP_BINARY), |
||
46 | escapeshellarg(base_path('klinge')), |
||
47 | 'tasks:run' |
||
48 | ); |
||
49 | |||
50 | if ($this->option('run-output-file')) { |
||
51 | $command .= ' >> ' . escapeshellarg($this->option('run-output-file')) . ' 2>&1'; |
||
52 | } |
||
53 | |||
54 | while (true) { |
||
55 | usleep(100 * 1000); |
||
56 | |||
57 | if (intval(Date::now()->getSecond()) === 0 && ! Date::now()->startOfMinute()->equalTo($lastExecutionStartedAt)) { |
||
58 | $executions[] = $execution = Process::fromShellCommandline($command); |
||
59 | |||
60 | $execution->start(); |
||
61 | |||
62 | $lastExecutionStartedAt = Date::now()->startOfMinute(); |
||
63 | } |
||
64 | |||
65 | foreach ($executions as $key => $execution) { |
||
66 | $output = $execution->getIncrementalOutput(). $execution->getIncrementalErrorOutput(); |
||
67 | |||
68 | $this->write(ltrim($output, "\n"))->eol(); |
||
69 | |||
70 | if (! $execution->isRunning()) { |
||
71 | unset($executions[$key]); |
||
72 | } |
||
77 |