|
@@ -17,7 +17,6 @@ use Symfony\Component\Console\Input\InputInterface;
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
|
-use Throwable;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* CLI Command to run the cron-jobs.
|
|
* CLI Command to run the cron-jobs.
|
|
@@ -55,7 +54,11 @@ class CronCommand extends Command
|
|
|
/** @noinspection PhpUnused */
|
|
/** @noinspection PhpUnused */
|
|
|
#[Required]
|
|
#[Required]
|
|
|
/** @see https://symfony.com/doc/current/logging/channels_handlers.html#how-to-autowire-logger-channels */
|
|
/** @see https://symfony.com/doc/current/logging/channels_handlers.html#how-to-autowire-logger-channels */
|
|
|
- public function setLoggerInterface(LoggerInterface $cronLogger): void { $this->logger = $cronLogger; }
|
|
|
|
|
|
|
+ public function setLoggerInterface(LoggerInterface $cronLogger): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->logger = $cronLogger;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/** @noinspection PhpUnused */
|
|
/** @noinspection PhpUnused */
|
|
|
#[Required]
|
|
#[Required]
|
|
|
public function setCronjobIterator(CronjobIterator $cronjobIterator): void
|
|
public function setCronjobIterator(CronjobIterator $cronjobIterator): void
|
|
@@ -144,7 +147,7 @@ class CronCommand extends Command
|
|
|
|
|
|
|
|
foreach ($jobs as $job) {
|
|
foreach ($jobs as $job) {
|
|
|
$this->logger->info(
|
|
$this->logger->info(
|
|
|
- 'CronCommand will execute `' . $job->name() . '`' . ($preview ? ' [PREVIEW MODE]' : '')
|
|
|
|
|
|
|
+ 'CronCommand will execute `'.$job->name().'`'.($preview ? ' [PREVIEW MODE]' : '')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
$results[] = $this->runJob($job, $preview);
|
|
$results[] = $this->runJob($job, $preview);
|
|
@@ -209,15 +212,14 @@ class CronCommand extends Command
|
|
|
|
|
|
|
|
$t1 = microtime(true);
|
|
$t1 = microtime(true);
|
|
|
|
|
|
|
|
- $msg = "Job has been successfully executed (" . round($t1 - $t0, 2) . " sec.)" . ($preview ? ' [PREVIEW MODE]' : '');
|
|
|
|
|
|
|
+ $msg = 'Job has been successfully executed ('.round($t1 - $t0, 2).' sec.)'.($preview ? ' [PREVIEW MODE]' : '');
|
|
|
$this->output->writeln($formatter->formatSection($job->name(), $msg));
|
|
$this->output->writeln($formatter->formatSection($job->name(), $msg));
|
|
|
- $this->logger->info($job->name() . ' - ' . $msg);
|
|
|
|
|
-
|
|
|
|
|
- } catch (Throwable $e) {
|
|
|
|
|
|
|
+ $this->logger->info($job->name().' - '.$msg);
|
|
|
|
|
+ } catch (\Throwable $e) {
|
|
|
$this->logger->critical($e);
|
|
$this->logger->critical($e);
|
|
|
- $this->output->write("An error happened while running the process : " . $e);
|
|
|
|
|
- return Command::FAILURE;
|
|
|
|
|
|
|
+ $this->output->write('An error happened while running the process : '.$e);
|
|
|
|
|
|
|
|
|
|
+ return Command::FAILURE;
|
|
|
} finally {
|
|
} finally {
|
|
|
$this->resetLoggerFormatter();
|
|
$this->resetLoggerFormatter();
|
|
|
}
|
|
}
|
|
@@ -226,18 +228,15 @@ class CronCommand extends Command
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Modify the RotatingFile logger line format to match the display the current job's name (if any)
|
|
|
|
|
- *
|
|
|
|
|
- * @param string|null $jobName
|
|
|
|
|
- * @return void
|
|
|
|
|
|
|
+ * Modify the RotatingFile logger line format to match the display the current job's name (if any).
|
|
|
*/
|
|
*/
|
|
|
- protected function configureLoggerFormatter(string | null $jobName = null): void {
|
|
|
|
|
- /** @noinspection PhpPossiblePolymorphicInvocationInspection @phpstan-ignore-next-line */
|
|
|
|
|
|
|
+ protected function configureLoggerFormatter(?string $jobName = null): void
|
|
|
|
|
+ {
|
|
|
|
|
+ /* @noinspection PhpPossiblePolymorphicInvocationInspection @phpstan-ignore-next-line */
|
|
|
foreach ($this->logger->getHandlers() as $handler) {
|
|
foreach ($this->logger->getHandlers() as $handler) {
|
|
|
if ($handler instanceof RotatingFileHandler) {
|
|
if ($handler instanceof RotatingFileHandler) {
|
|
|
-
|
|
|
|
|
- $format = "[%datetime%] " .
|
|
|
|
|
- ($jobName !== null ? "[" . $jobName . "] " : "") .
|
|
|
|
|
|
|
+ $format = '[%datetime%] '.
|
|
|
|
|
+ ($jobName !== null ? '['.$jobName.'] ' : '').
|
|
|
"%channel%.%level_name%: %message% %context% %extra%\n";
|
|
"%channel%.%level_name%: %message% %context% %extra%\n";
|
|
|
|
|
|
|
|
$handler->setFormatter(new LineFormatter($format, 'Y-m-d H:i:s.v'));
|
|
$handler->setFormatter(new LineFormatter($format, 'Y-m-d H:i:s.v'));
|
|
@@ -246,8 +245,7 @@ class CronCommand extends Command
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Alias for `$this->configureLoggerFormatter(null)`
|
|
|
|
|
- * @return void
|
|
|
|
|
|
|
+ * Alias for `$this->configureLoggerFormatter(null)`.
|
|
|
*/
|
|
*/
|
|
|
protected function resetLoggerFormatter(): void
|
|
protected function resetLoggerFormatter(): void
|
|
|
{
|
|
{
|