Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Nov 18, 2023
2 parents 00434a4 + ca61625 commit a4f725e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
30 changes: 17 additions & 13 deletions app/modules/Monolog/Interfaces/TCP/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
namespace Modules\Monolog\Interfaces\TCP;

use App\Application\Commands\HandleReceivedEvent;
use Psr\Log\LoggerInterface;
use Spiral\Cqrs\CommandBusInterface;
use Spiral\Exceptions\ExceptionReporterInterface;
use Spiral\RoadRunner\Tcp\Request;
use Spiral\RoadRunner\Tcp\TcpEvent;
use Spiral\RoadRunnerBridge\Tcp\Response\CloseConnection;
use Spiral\RoadRunnerBridge\Tcp\Response\ContinueRead;
use Spiral\RoadRunnerBridge\Tcp\Response\ResponseInterface;
use Spiral\RoadRunnerBridge\Tcp\Service\ServiceInterface;

class Service implements ServiceInterface
final class Service implements ServiceInterface
{
public function __construct(
private readonly CommandBusInterface $commandBus,
private readonly LoggerInterface $logger,
) {
}

Expand All @@ -33,19 +36,20 @@ public function handle(Request $request): ResponseInterface
$messages = \array_filter(\explode("\n", $request->body));

foreach ($messages as $message) {
$payload = \json_decode($message, true);

// Impossible to decode the message, give up.
if (!$payload) {
throw new \RuntimeException("Unable to decode a message from [{$request->connectionUuid}] client.");
try {
$payload = \json_decode($message, true, JSON_THROW_ON_ERROR);
$this->commandBus->dispatch(
new HandleReceivedEvent(
type: 'monolog',
payload: $payload,
),
);
} catch (\JsonException $e) {
// Impossible to decode the message, give up.
$this->logger->error("Unable to decode log message. Should be a valid JSON.", [
'message' => $message,
]);
}

$this->commandBus->dispatch(
new HandleReceivedEvent(
type: 'monolog',
payload: $payload
)
);
}

return new ContinueRead();
Expand Down
3 changes: 1 addition & 2 deletions app/modules/Ray/Application/Handlers/MergeEventsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public function handle(array $event): array
...($storedEvent->getPayload()->jsonSerialize()['payloads'] ?? []),
...($event['payloads'] ?? [])
];
} catch (EntityNotFoundException) {
}
} catch (EntityNotFoundException) {}

return $event;
}
Expand Down
2 changes: 1 addition & 1 deletion app/modules/Ray/Interfaces/Http/Handler/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Application\Domain\ValueObjects\Uuid;
use App\Application\Service\HttpHandler\HandlerInterface;
use Carbon\CarbonInterval;
use Modules\Profiler\Application\EventHandlerInterface;
use Modules\Ray\Application\EventHandlerInterface;
use Modules\Ray\Application\TypeEnum;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down

0 comments on commit a4f725e

Please sign in to comment.