Added logging.
This commit is contained in:
@ -1,13 +1,19 @@
|
||||
<?php
|
||||
namespace App\Rclone;
|
||||
|
||||
use Psr\Log\LoggerAwareTrait;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
|
||||
|
||||
use Exception;
|
||||
|
||||
class Rclone
|
||||
class Rclone
|
||||
{
|
||||
use LoggerAwareTrait;
|
||||
|
||||
protected string $rclonePath;
|
||||
/**
|
||||
* Global options
|
||||
@ -21,6 +27,7 @@ class Rclone
|
||||
function __construct(string $rclonePath = "rclone")
|
||||
{
|
||||
$this->rclonePath = $rclonePath;
|
||||
$this->setLogger(new NullLogger);
|
||||
try
|
||||
{
|
||||
$version = $this->exec('--version');
|
||||
@ -28,7 +35,6 @@ class Rclone
|
||||
catch(ProcessFailedException $e)
|
||||
{
|
||||
throw new Exception("Check installation of rclone");
|
||||
return;
|
||||
}
|
||||
|
||||
$this->version = explode("\n", $version)[0];
|
||||
@ -68,7 +74,7 @@ class Rclone
|
||||
* @param array<String> $options
|
||||
*/
|
||||
protected function exec(string $command, array $options = array()) : string
|
||||
{
|
||||
{
|
||||
$process = new Process(
|
||||
array_merge(
|
||||
[$this->rclonePath],
|
||||
@ -77,14 +83,16 @@ class Rclone
|
||||
$options
|
||||
)
|
||||
);
|
||||
$this->logger->info("Execute command", [$process->getCommandLine()]);
|
||||
$process->setTimeout(4*3600);
|
||||
$process->run();
|
||||
|
||||
// executes after the command finishes
|
||||
if (!$process->isSuccessful()) {
|
||||
$this->logger->error("Failed execution");
|
||||
throw new ProcessFailedException($process);
|
||||
}
|
||||
|
||||
$this->logger->info("Return code", [$process->getExitCode()]);
|
||||
return $process->getOutput();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user