Compare commits
2 Commits
13b246b998
...
d10ee33215
Author | SHA1 | Date | |
---|---|---|---|
d10ee33215 | |||
5134630525 |
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Common\Implement\Log\Formatter;
|
namespace Incoviba\Common\Implement\Log\Formatter;
|
||||||
|
|
||||||
|
use Throwable;
|
||||||
use Monolog\Formatter\JsonFormatter;
|
use Monolog\Formatter\JsonFormatter;
|
||||||
use Monolog\LogRecord;
|
use Monolog\LogRecord;
|
||||||
|
|
||||||
@ -13,7 +14,35 @@ class PDO extends JsonFormatter
|
|||||||
|
|
||||||
public function format(LogRecord $record): string
|
public function format(LogRecord $record): string
|
||||||
{
|
{
|
||||||
|
if (is_a($record->message, Throwable::class)) {
|
||||||
|
$exception = $record->message;
|
||||||
|
$message = $this->normalizeException($exception);
|
||||||
|
$context = $record->context;
|
||||||
|
$context['exception'] = $exception;
|
||||||
|
if ($exception->getPrevious()) {
|
||||||
|
$context['previous'] = $this->walkException($exception);
|
||||||
|
}
|
||||||
|
$new_record = new LogRecord(
|
||||||
|
$record->datetime,
|
||||||
|
$record->channel,
|
||||||
|
$record->level,
|
||||||
|
json_encode($message),
|
||||||
|
$context,
|
||||||
|
$record->extra
|
||||||
|
);
|
||||||
|
$record = $new_record;
|
||||||
|
}
|
||||||
$normalized = $this->normalize($record, $this->maxNormalizeDepth);
|
$normalized = $this->normalize($record, $this->maxNormalizeDepth);
|
||||||
return $normalized['message'];
|
return $normalized['message'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function walkException(Throwable $exception, int $depth = 0): array
|
||||||
|
{
|
||||||
|
$output = [];
|
||||||
|
$currentDepth = $depth;
|
||||||
|
while ($previous = $exception->getPrevious() and $currentDepth < $this->maxNormalizeDepth) {
|
||||||
|
$output []= $this->normalizeException($previous);
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use DateTimeZone;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use OutOfRangeException;
|
use OutOfRangeException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Predis\Connection\ConnectionException;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
@ -36,7 +37,7 @@ class Job extends Ideal\Service
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return array_map([$this, 'load'], $jobs);
|
return array_map([$this, 'load'], $jobs);
|
||||||
} catch (EmptyRedis) {
|
} catch (ConnectionException | EmptyRedis) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class Queue extends Ideal\Service
|
|||||||
try {
|
try {
|
||||||
$this->jobService->add($configuration);
|
$this->jobService->add($configuration);
|
||||||
return true;
|
return true;
|
||||||
} catch (Create $exception) {
|
} catch (Read $exception) {
|
||||||
$final = new Exception("Could not enqueue job", 0, $exception);
|
$final = new Exception("Could not enqueue job", 0, $exception);
|
||||||
$this->logger->warning($final);
|
$this->logger->warning($final);
|
||||||
return false;
|
return false;
|
||||||
@ -82,12 +82,10 @@ class Queue extends Ideal\Service
|
|||||||
}
|
}
|
||||||
public function run(?RequestInterface $request = null): bool
|
public function run(?RequestInterface $request = null): bool
|
||||||
{
|
{
|
||||||
try {
|
$jobs = $this->jobService->getPending();
|
||||||
$jobs = $this->jobService->getPending();
|
if (count($jobs) === 0) {
|
||||||
} catch (Read $exception) {
|
$this->logger->debug("No pending jobs");
|
||||||
$final = new Exception("Could not get pending jobs", 0, $exception);
|
return true;
|
||||||
$this->logger->warning($final);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
namespace Incoviba\Service;
|
namespace Incoviba\Service;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Predis\Connection\ConnectionException;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Predis\Connection\ConnectionException;
|
||||||
|
|
||||||
class Job
|
class Job
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user