Skip to content

Commit 1f6915b

Browse files
authored
Merge pull request #298 from buggregator/feature/var-dumper-server
Migrate var-dumper server to RoadRunner plugin
2 parents 00c6b3d + 884417a commit 1f6915b

9 files changed

Lines changed: 40 additions & 270 deletions

File tree

.docker/velox.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ repository = "tcp"
9393
[github.plugins.smtp-server]
9494
ref = "2.0.0"
9595
owner = "buggregator"
96-
repository = "smtp-server"
96+
repository = "smtp-server"
97+
98+
[github.plugins.var-dumper-server]
99+
ref = "1.0.0"
100+
owner = "buggregator"
101+
repository = "var-dumper-server"

.rr-prod.yaml

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,26 @@ server:
1313
command: "php app.php register:modules"
1414

1515
logs:
16-
# Logging mode can be "development", "production" or "raw".
17-
# Do not forget to change this value for production environment.
1816
mode: ${RR_LOG_MODE:-production}
19-
# Encoding format can be "console" or "json" (last is preferred for production usage).
2017
encoding: ${RR_LOG_ENCODING:-json}
21-
# Logging level can be "panic", "error", "warn", "info", "debug".
2218
level: ${RR_LOG_LEVEL:-warn}
2319
channels:
2420
http:
25-
# HTTP plugin logging level can be "panic", "error", "warn", "info", "debug".
2621
level: ${RR_LOG_HTTP_LEVEL:-warn}
2722
tcp:
28-
# TCP plugin logging level can be "panic", "error", "warn", "info", "debug".
2923
level: ${RR_LOG_TCP_LEVEL:-warn}
3024
jobs:
31-
# JOBS plugin logging level can be "panic", "error", "warn", "info", "debug".
3225
level: ${RR_LOG_JOBS_LEVEL:-warn}
3326
centrifuge:
34-
# Centrifuge plugin logging level can be "panic", "error", "warn", "info", "debug".
3527
level: ${RR_LOG_CENTRIFUGE_LEVEL:-warn}
3628
server:
37-
# Server logging level can be "panic", "error", "warn", "info", "debug".
3829
level: ${RR_LOG_SERVER_LEVEL:-warn}
3930
service:
40-
# Service logging level can be "panic", "error", "warn", "info", "debug".
4131
level: ${RR_LOG_SERVICE_LEVEL:-warn}
32+
smtp:
33+
level: ${RR_LOG_SMTP_LEVEL:-warn}
34+
var-dumper:
35+
level: ${RR_LOG_VAR_DUMPER_LEVEL:-warn}
4236

4337
http:
4438
address: 127.0.0.1:8082
@@ -57,20 +51,11 @@ http:
5751
tcp:
5852
servers:
5953
monolog:
60-
# Address to listen.
6154
addr: ${RR_TCP_MONOLOG_ADDR:-:9913}
6255
delimiter: "\n"
63-
var-dumper:
64-
# Address to listen.
65-
addr: ${RR_TCP_VAR_DUMPER_ADDR:-:9912}
66-
delimiter: "\n"
67-
# Chunks that RR uses to read the data. In bytes.
68-
# If you expect big payloads on a TCP server, to reduce `read` syscalls,
69-
# would be a good practice to use a fairly big enough buffer.
70-
# Default: 1024 * 1024 * 50 (50MB)
7156
read_buf_size: ${RR_TCP_READ_BUF_SIZE:-50485760}
7257
pool:
73-
num_workers: ${RR_TCP_NUM_WORKERS:-2}
58+
num_workers: ${RR_TCP_NUM_WORKERS:-1}
7459

7560
kv:
7661
local:
@@ -79,9 +64,9 @@ kv:
7964

8065
jobs:
8166
consume:
82-
- smtp
67+
- events
8368
pipelines:
84-
smtp:
69+
events:
8570
driver: memory
8671
config:
8772
priority: 10
@@ -93,7 +78,13 @@ smtp:
9378
addr: ${RR_SMTP_ADDR:-:1025}
9479
hostname: "buggregator.local"
9580
jobs:
96-
pipeline: smtp
81+
pipeline: events
82+
83+
var-dumper:
84+
addr: ${RR_VAR_DUMPER_ADDR:-:9912}
85+
max_message_size: ${RR_TCP_READ_BUF_SIZE:-50485760}
86+
jobs:
87+
pipeline: events
9788

9889
service:
9990
nginx:

app/config/queue.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Modules\Smtp\Interfaces\Jobs\EmailHandler;
6+
use Modules\VarDumper\Interfaces\Jobs\DumpHandler;
67
use Modules\Webhooks\Interfaces\Job\WebhookHandler;
78
use Spiral\Queue\Driver\SyncDriver;
89
use Spiral\RoadRunner\Jobs\Queue\MemoryCreateInfo;
@@ -39,6 +40,7 @@
3940
'registry' => [
4041
'handlers' => [
4142
'smtp.email' => EmailHandler::class,
43+
'vardumper.dump' => DumpHandler::class,
4244
],
4345
'serializers' => [
4446
WebhookHandler::class => 'symfony-json',

app/config/tcp.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
declare(strict_types=1);
44

55
use App\Application\TCP\ExceptionHandlerInterceptor;
6-
use Modules\VarDumper\Interfaces\TCP\Service as VarDumperService;
76
use Modules\Monolog\Interfaces\TCP\Service as MonologService;
87

98
return [
109
'services' => [
11-
'var-dumper' => VarDumperService::class,
1210
'monolog' => MonologService::class,
1311
],
1412

app/modules/VarDumper/Interfaces/TCP/Service.php renamed to app/modules/VarDumper/Interfaces/Jobs/DumpHandler.php

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Modules\VarDumper\Interfaces\TCP;
5+
namespace Modules\VarDumper\Interfaces\Jobs;
66

77
use App\Application\Commands\HandleReceivedEvent;
88
use Modules\VarDumper\Application\Dump\BodyInterface;
@@ -12,41 +12,32 @@
1212
use Modules\VarDumper\Application\Dump\MessageParser;
1313
use Modules\VarDumper\Application\Dump\ParsedPayload;
1414
use Modules\VarDumper\Application\Dump\PrimitiveBody;
15+
use Spiral\Core\InvokerInterface;
1516
use Spiral\Cqrs\CommandBusInterface;
16-
use Spiral\RoadRunner\Tcp\Request;
17-
use Spiral\RoadRunner\Tcp\TcpEvent;
18-
use Spiral\RoadRunnerBridge\Tcp\Response\ContinueRead;
19-
use Spiral\RoadRunnerBridge\Tcp\Response\ResponseInterface;
20-
use Spiral\RoadRunnerBridge\Tcp\Service\ServiceInterface;
17+
use Spiral\Queue\JobHandler;
2118
use Symfony\Component\VarDumper\Cloner\Data;
2219

23-
final readonly class Service implements ServiceInterface
20+
final class DumpHandler extends JobHandler
2421
{
2522
public function __construct(
26-
private CommandBusInterface $commandBus,
27-
private DumpIdGeneratorInterface $dumpId,
28-
) {}
23+
private readonly CommandBusInterface $bus,
24+
private readonly DumpIdGeneratorInterface $dumpId,
25+
InvokerInterface $invoker,
26+
) {
27+
parent::__construct($invoker);
28+
}
2929

30-
public function handle(Request $request): ResponseInterface
30+
public function invoke(mixed $payload): void
3131
{
32-
if ($request->event === TcpEvent::Connected) {
33-
return new ContinueRead();
34-
}
35-
36-
$messages = \array_filter(\explode("\n", $request->body));
37-
38-
foreach ($messages as $message) {
39-
$payload = (new MessageParser())->parse($message);
40-
41-
$this->fireEvent($payload);
42-
}
43-
44-
return new ContinueRead();
32+
$this->fireEvent(
33+
(new MessageParser())->parse($payload),
34+
);
4535
}
4636

37+
4738
private function fireEvent(ParsedPayload $payload): void
4839
{
49-
$this->commandBus->dispatch(
40+
$this->bus->dispatch(
5041
new HandleReceivedEvent(
5142
type: 'var-dump',
5243
payload: [
@@ -96,4 +87,5 @@ private function prepareContent(ParsedPayload $payload): array
9687

9788
return $payloadContent;
9889
}
90+
9991
}

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ services:
3131
args:
3232
GH_TOKEN: "${GH_TOKEN}"
3333
environment:
34-
# RR_LOG_LEVEL: debug
34+
RR_LOG_LEVEL: debug
3535
# RR_LOG_TCP_LEVEL: debug
3636
# RR_LOG_JOBS_LEVEL: debug
3737
# RR_LOG_SERVER_LEVEL: debug

tests/Feature/Interfaces/TCP/TCPTestCase.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55
namespace Tests\Feature\Interfaces\TCP;
66

77
use Modules\Monolog\Interfaces\TCP\Service as MonologService;
8-
use Modules\VarDumper\Interfaces\TCP\Service as VarDumperService;
9-
use Modules\Smtp\Interfaces\TCP\Service as SmtpService;
10-
use Ramsey\Uuid\Uuid;
11-
use Ramsey\Uuid\UuidInterface;
128
use Spiral\RoadRunner\Tcp\Request;
139
use Spiral\RoadRunner\Tcp\TcpEvent;
1410
use Spiral\RoadRunnerBridge\Tcp\Response\ResponseInterface;
15-
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
16-
use Tests\App\Smtp\FakeStream;
1711
use Tests\DatabaseTestCase;
1812

1913
abstract class TCPTestCase extends DatabaseTestCase
@@ -25,20 +19,6 @@ public function handleMonologRequest(string $message): ResponseInterface
2519
->handle($this->buildRequest(message: $message));
2620
}
2721

28-
public function handleVarDumperRequest(string $message): ResponseInterface
29-
{
30-
return $this
31-
->get(VarDumperService::class)
32-
->handle($this->buildRequest(message: $message));
33-
}
34-
35-
public function handleSmtpRequest(string $message, TcpEvent $event = TcpEvent::Data): ResponseInterface
36-
{
37-
return $this
38-
->get(SmtpService::class)
39-
->handle($this->buildRequest(message: $message, event: $event));
40-
}
41-
4222
private function buildRequest(string $message, TcpEvent $event = TcpEvent::Data): Request
4323
{
4424
return new Request(
@@ -49,19 +29,4 @@ private function buildRequest(string $message, TcpEvent $event = TcpEvent::Data)
4929
server: 'localhost',
5030
);
5131
}
52-
53-
protected function buildSmtpClient(string $username = 'homestead', ?UuidInterface $uuid = null): EsmtpTransport
54-
{
55-
$client = new EsmtpTransport(
56-
stream: new FakeStream(
57-
service: $this->get(SmtpService::class),
58-
uuid: (string) $uuid ?? Uuid::uuid7(),
59-
),
60-
);
61-
62-
$client->setUsername($username);
63-
$client->setPassword('password');
64-
65-
return $client;
66-
}
6732
}

tests/Feature/Interfaces/TCP/VarDumper/SymfonyV6Test.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)