log message if the task command is stuck
This commit is contained in:
@@ -11,6 +11,8 @@ use App\Libs\Exceptions\RuntimeException;
|
||||
use App\Listeners\ProcessProfileEvent;
|
||||
use Closure;
|
||||
use DirectoryIterator;
|
||||
use Monolog\Level;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Command\Command as BaseCommand;
|
||||
use Symfony\Component\Console\Command\LockableTrait;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
@@ -130,19 +132,24 @@ class Command extends BaseCommand
|
||||
*
|
||||
* @param Closure $closure The closure to be executed.
|
||||
* @param iOutput $output The OutputInterface instance for writing output messages.
|
||||
* @param array $opts (Optional) Additional options to pass to the closure.
|
||||
*
|
||||
* @return int The return value of the closure.
|
||||
*/
|
||||
protected function single(Closure $closure, iOutput $output): int
|
||||
protected function single(Closure $closure, iOutput $output, array $opts = []): int
|
||||
{
|
||||
try {
|
||||
if (!$this->lock(getAppVersion() . ':' . $this->getName())) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
'<error>The command \'%s\' is already running in another process.</error>',
|
||||
$this->getName()
|
||||
)
|
||||
);
|
||||
$message = r("The command/task '{name}' is already running in another process.", [
|
||||
'name' => $this->getName()
|
||||
]);
|
||||
|
||||
$output->writeln("<error>$message</error>");
|
||||
|
||||
if (null !== ($logger = ag($opts, iLogger::class))) {
|
||||
assert($logger instanceof iLogger);
|
||||
$logger->log(ag($opts, Level::class, Level::Notice), $message);
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -7,17 +7,18 @@ namespace App\Commands\Backend;
|
||||
use App\Command;
|
||||
use App\Libs\Attributes\Route\Cli;
|
||||
use App\Libs\Config;
|
||||
use App\Libs\Extends\StreamLogHandler;
|
||||
use App\Libs\LogSuppressor;
|
||||
use App\Libs\Enums\Http\Status;
|
||||
use App\Libs\Exceptions\RuntimeException;
|
||||
use App\Libs\Extends\StreamLogHandler;
|
||||
use App\Libs\LogSuppressor;
|
||||
use App\Libs\Mappers\Import\RestoreMapper;
|
||||
use App\Libs\Message;
|
||||
use App\Libs\Options;
|
||||
use App\Libs\Stream;
|
||||
use App\Libs\QueueRequests;
|
||||
use App\Libs\Stream;
|
||||
use App\Libs\UserContext;
|
||||
use DirectoryIterator;
|
||||
use Monolog\Level;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
@@ -153,7 +154,10 @@ class RestoreCommand extends Command
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output);
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output, [
|
||||
iLogger::class => $this->logger,
|
||||
Level::class => Level::Error,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,10 +252,13 @@ class RestoreCommand extends Command
|
||||
return self::SUCCESS;
|
||||
}
|
||||
} else {
|
||||
$this->logger->notice("The restore target '{user}@{backend}' has import enabled, which means the changes will propagate back to the other backends.", [
|
||||
'user' => $userContext->name,
|
||||
'backend' => $name,
|
||||
]);
|
||||
$this->logger->notice(
|
||||
"The restore target '{user}@{backend}' has import enabled, which means the changes will propagate back to the other backends.",
|
||||
[
|
||||
'user' => $userContext->name,
|
||||
'backend' => $name,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +288,9 @@ class RestoreCommand extends Command
|
||||
);
|
||||
|
||||
if (false === $input->getOption('execute')) {
|
||||
$this->logger->notice("No changes will be committed to backend. To execute the changes pass '--execute' flag option.");
|
||||
$this->logger->notice(
|
||||
"No changes will be committed to backend. To execute the changes pass '--execute' flag option."
|
||||
);
|
||||
}
|
||||
|
||||
$opts = [
|
||||
|
||||
@@ -41,6 +41,7 @@ use App\Libs\Entity\StateInterface as iState;
|
||||
use App\Libs\Options;
|
||||
use Closure;
|
||||
use InvalidArgumentException;
|
||||
use Monolog\Level;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Input\InputInterface as iInput;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
@@ -111,7 +112,10 @@ final class TestCommand extends Command
|
||||
*/
|
||||
protected function runCommand(iInput $input, iOutput $output): int
|
||||
{
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output);
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output, [
|
||||
iLogger::class => $this->logger,
|
||||
Level::class => Level::Error,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,8 +13,9 @@ use App\Libs\Mappers\Import\DirectMapper;
|
||||
use App\Libs\Options;
|
||||
use App\Libs\Stream;
|
||||
use App\Libs\UserContext;
|
||||
use Psr\Http\Message\StreamInterface as iStream;
|
||||
use Monolog\Level;
|
||||
use Monolog\Logger;
|
||||
use Psr\Http\Message\StreamInterface as iStream;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Input\InputInterface as iInput;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
@@ -178,7 +179,10 @@ class BackupCommand extends Command
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->single(fn(): int => $this->process($input), $output);
|
||||
return $this->single(fn(): int => $this->process($input), $output, [
|
||||
iLogger::class => $this->logger,
|
||||
Level::class => Level::Error,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,9 +381,9 @@ class BackupCommand extends Command
|
||||
array_push(
|
||||
$queue,
|
||||
...$backend['class']->backup($userContext->mapper, $backend['fp'] ?? null, [
|
||||
'no_enhance' => true === $input->getOption('no-enhance'),
|
||||
Options::DRY_RUN => (bool)$input->getOption('dry-run'),
|
||||
])
|
||||
'no_enhance' => true === $input->getOption('no-enhance'),
|
||||
Options::DRY_RUN => (bool)$input->getOption('dry-run'),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ use App\Libs\Options;
|
||||
use App\Libs\QueueRequests;
|
||||
use App\Libs\Stream;
|
||||
use App\Libs\UserContext;
|
||||
use Monolog\Level;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -136,7 +137,10 @@ class ExportCommand extends Command
|
||||
*/
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output);
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output, [
|
||||
iLogger::class => $this->logger,
|
||||
Level::class => Level::Error,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ use App\Libs\Message;
|
||||
use App\Libs\Options;
|
||||
use App\Libs\Stream;
|
||||
use App\Libs\UserContext;
|
||||
use Monolog\Level;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
@@ -238,7 +239,10 @@ class ImportCommand extends Command
|
||||
*/
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output);
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output, [
|
||||
iLogger::class => $this->logger,
|
||||
Level::class => Level::Error,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user