Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ The queue system uses logs to ensure maintainability and implements retry featur

## Version History

| Branch | Release | PSR-11 | OSS Lifecycle | PHP Version |
|--------|---------|--------|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| Branch | Release | PSR-11 | OSS Lifecycle | PHP Version |
|--------|---------|--------|-----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| 2.0 | `> 2.0` | 1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/queue) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/queue/2.0.0) |
| 1.0 | `< 2.0` | 1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/queue) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/queue/1.0.0) |

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"roave/security-advisories": "dev-master",
"swoole/ide-helper": "~6.0.0"
},
"conflict": {
"symfony/polyfill-php83": "<1.30"
},
"autoload": {
"psr-4": {
"Queue\\": "src/"
Expand Down
12 changes: 1 addition & 11 deletions src/App/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@
class Message
{
public function __construct(
private array $payload,
public array $payload,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergiuBota1 Based on your experience with Dotkernel Queue, does a message need to change after it was initialized? Did you ever need to add/overwrite keys/values?

If not, then $payload (or rather the Message class itself) should become readonly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we do this inside the handler for the purpose of logging the retry, before using the retry functionality provided by Symfony Messenger we used a custom approach that involved storing the retry count in the payload. If I recall correctly, the goal was to have every failed attempt recorded in the log file, we probably need to rethink this and extract everything we need from the envelope while keeping the payload readonly.

) {
}

public function getPayload(): array
{
return $this->payload;
}

public function setPayload(array $payload): void
{
$this->payload = $payload;
}
}
4 changes: 2 additions & 2 deletions src/App/Message/MessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
*/
public function __invoke(Message $message): void
{
$payload = $message->getPayload();
$payload = $message->payload;

try {
if ($payload['foo'] === 'control') {
Expand All @@ -52,7 +52,7 @@ public function __invoke(Message $message): void
}

$payload['retry_count'] = $retryCount + 1;
$message->setPayload($payload);
$message->payload = $payload;

throw $e;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Swoole/Command/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class StartCommand extends Command

public PidManager $pidManager;

public const DEFAULT_PROCESS_NAME = 'dotkernel-queue';
public const string DEFAULT_PROCESS_NAME = 'dotkernel-queue';

public const HELP = <<<'EOH'
public const string HELP = <<<'EOH'
Start the web server. If --daemonize is provided, starts the server as a
background process and returns handling to the shell; otherwise, the
server runs in the current process.
Expand Down
2 changes: 1 addition & 1 deletion src/Swoole/Command/StopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StopCommand extends Command
{
use IsRunningTrait;

public const HELP = <<<'EOH'
public const string HELP = <<<'EOH'
Stop the web server. Kills all worker processes and stops the web server.

This command is only relevant when the server was started using the
Expand Down
2 changes: 1 addition & 1 deletion src/Swoole/PidManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class PidManager
{
public function __construct(private string $pidFile)
public function __construct(private readonly string $pidFile)
{
}

Expand Down
14 changes: 4 additions & 10 deletions src/Swoole/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,16 @@

class ServerFactory
{
/**
* @var string
*/
public const DEFAULT_HOST = '127.0.0.1';
public const string DEFAULT_HOST = '127.0.0.1';

/**
* @var int
*/
public const DEFAULT_PORT = 8080;
public const int DEFAULT_PORT = 8080;

/**
* Swoole server supported modes
*
* @var int[]
*/
private const MODES = [
private const array MODES = [
SWOOLE_BASE,
SWOOLE_PROCESS,
];
Expand All @@ -56,7 +50,7 @@ class ServerFactory
*
* @var int[]
*/
private const PROTOCOLS = [
private const array PROTOCOLS = [
SWOOLE_SOCK_TCP,
SWOOLE_SOCK_TCP6,
SWOOLE_SOCK_UDP,
Expand Down
6 changes: 3 additions & 3 deletions test/App/Message/MessageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testControlMessageDoesNotThrowAndDoesNotSetRetryCount(): void
$message = new Message(['foo' => 'control']);
$handler($message);

$payload = $message->getPayload();
$payload = $message->payload;
$this->assertArrayNotHasKey('retry_count', $payload);
}

Expand All @@ -81,7 +81,7 @@ public function testRetryMessageThrowsExceptionAndSetsRetryCount(): void
try {
$handler($message);
} finally {
$payload = $message->getPayload();
$payload = $message->payload;
$this->assertArrayHasKey('retry_count', $payload);
$this->assertEquals(1, $payload['retry_count']); // first retry
}
Expand All @@ -101,7 +101,7 @@ public function testRetryMessageWithExistingRetryCountIncrementsIt(): void
try {
$handler($message);
} finally {
$payload = $message->getPayload();
$payload = $message->payload;
$this->assertEquals(3, $payload['retry_count']); // incremented from 2 → 3
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/App/Message/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class MessageTest extends TestCase
public function testMessageAccessors(): void
{
$admin = new Message(['payload' => 'test message payload']);
$this->assertSame(['payload' => 'test message payload'], $admin->getPayload());
$this->assertSame(['payload' => 'test message payload'], $admin->payload);
}
}
4 changes: 2 additions & 2 deletions test/Swoole/Delegators/TCPServerDelegatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ public function testReceiveDispatchesMessagesAndLogsWhenUnknownCommand(): void

if ($callCount === 1) {
$this->assertInstanceOf(Message::class, $message);
$this->assertEquals('hello', $message->getPayload()['foo']);
$this->assertEquals('hello', $message->payload['foo']);
} elseif ($callCount === 2) {
$this->assertInstanceOf(Message::class, $message);
$this->assertEquals('with 5 seconds delay', $message->getPayload()['foo']);
$this->assertEquals('with 5 seconds delay', $message->payload['foo']);
} else {
$this->fail('dispatch called more than twice');
}
Expand Down
Loading