Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions src/Commands/Work.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace BlitzPHP\Tasks\Commands;

use BlitzPHP\Utilities\Date;
use Symfony\Component\Process\Process;

class Work extends TaskCommand
{
/**
* {@inheritDoc}
*/
protected $name = 'tasks:work';

/**
* {@inheritDoc}
*/
protected $options = [
'--run-output-file' => 'Le fichier vers lequel diriger la sortie de `tasks:run`.',
];

/**
* {@inheritDoc}
*/
protected $description = 'Démarre le planificateur de tâche et l\'exécute localement.';

/**
* {@inheritDoc}
*/
protected $required = [

Check failure on line 30 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Property BlitzPHP\Tasks\Commands\Work::$required type has no value type specified in iterable type array.

Check failure on line 30 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Property BlitzPHP\Tasks\Commands\Work::$required type has no value type specified in iterable type array.
'symfony/process:^7.2',
];

/**
* {@inheritDoc}
*/
public function execute(array $params)

Check failure on line 37 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Method BlitzPHP\Tasks\Commands\Work::execute() has no return type specified.

Check failure on line 37 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Method BlitzPHP\Tasks\Commands\Work::execute() has no return type specified.
{
$this->info('Exéctutions des tâches programmées.');

[$lastExecutionStartedAt, $executions] = [Date::now()->subMinutes(10), []];

$command = sprintf(
'%s %s %s',
escapeshellarg(PHP_BINARY),
escapeshellarg(base_path('klinge')),
'tasks:run'
);

if ($this->option('run-output-file')) {
$command .= ' >> ' . escapeshellarg($this->option('run-output-file')) . ' 2>&1';
}

while (true) {

Check failure on line 54 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

While loop condition is always true.

Check failure on line 54 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

While loop condition is always true.
usleep(100 * 1000);

if (intval(Date::now()->getSecond()) === 0 && ! Date::now()->startOfMinute()->equalTo($lastExecutionStartedAt)) {

Check failure on line 57 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Cannot call method startOfMinute() on BlitzPHP\Utilities\Date|string.

Check failure on line 57 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Cannot call method startOfMinute() on BlitzPHP\Utilities\Date|string.
$executions[] = $execution = Process::fromShellCommandline($command);

$execution->start();

$lastExecutionStartedAt = Date::now()->startOfMinute();

Check failure on line 62 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Cannot call method startOfMinute() on BlitzPHP\Utilities\Date|string.

Check failure on line 62 in src/Commands/Work.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Cannot call method startOfMinute() on BlitzPHP\Utilities\Date|string.
}

foreach ($executions as $key => $execution) {
$output = $execution->getIncrementalOutput(). $execution->getIncrementalErrorOutput();

$this->write(ltrim($output, "\n"))->eol();

if (! $execution->isRunning()) {
unset($executions[$key]);
}
}
}
}
}
Loading