From be41da623d1058a7c2fa65c1e8cbae6863cf5fd3 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Fri, 20 Sep 2024 18:03:54 +0500 Subject: [PATCH 01/17] Simplify envelopes --- src/Message/AbstractEnvelope.php | 61 +++++++++++++++++++ src/Message/EnvelopeInterface.php | 2 - src/Message/EnvelopeTrait.php | 52 ---------------- src/Message/IdEnvelope.php | 18 ++---- .../FailureHandling/FailureEnvelope.php | 19 +++--- tests/Unit/EnvelopeTest.php | 6 +- .../SendAgainMiddlewareTest.php | 13 ++-- 7 files changed, 81 insertions(+), 90 deletions(-) create mode 100644 src/Message/AbstractEnvelope.php delete mode 100644 src/Message/EnvelopeTrait.php diff --git a/src/Message/AbstractEnvelope.php b/src/Message/AbstractEnvelope.php new file mode 100644 index 00000000..ce5d63e4 --- /dev/null +++ b/src/Message/AbstractEnvelope.php @@ -0,0 +1,61 @@ +message = $message instanceof EnvelopeInterface ? $message->getMessage() : $message; + $this->metadata = $message->getMetadata(); + + if (is_array($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY])) { + $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = array_merge( + [static::class], + array_filter( + $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY], + static fn(string $class) => $class !== static::class, + ) + ); + } else { + $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = [static::class]; + } + } + + public function getMessage(): MessageInterface + { + return $this->message; + } + + public function getHandlerName(): string + { + return $this->message->getHandlerName(); + } + + public function getData(): mixed + { + return $this->message->getData(); + } + + public function getMetadata(): array + { + return ArrayHelper::merge( + $this->metadata, + $this->getEnvelopeMetadata(), + ); + } + + /** + * Metadata of the envelope + * + * @return array + */ + abstract protected function getEnvelopeMetadata(): array; +} diff --git a/src/Message/EnvelopeInterface.php b/src/Message/EnvelopeInterface.php index 7c58daa1..72d8cced 100644 --- a/src/Message/EnvelopeInterface.php +++ b/src/Message/EnvelopeInterface.php @@ -15,6 +15,4 @@ interface EnvelopeInterface extends MessageInterface public static function fromMessage(MessageInterface $message): self; public function getMessage(): MessageInterface; - - public function withMessage(MessageInterface $message): self; } diff --git a/src/Message/EnvelopeTrait.php b/src/Message/EnvelopeTrait.php deleted file mode 100644 index cc52cf15..00000000 --- a/src/Message/EnvelopeTrait.php +++ /dev/null @@ -1,52 +0,0 @@ -message; - } - - public function withMessage(MessageInterface $message): self - { - $instance = clone $this; - $instance->message = $message; - - return $instance; - } - - public function getHandlerName(): string - { - return $this->message->getHandlerName(); - } - - public function getData(): mixed - { - return $this->message->getData(); - } - - public function getMetadata(): array - { - return array_merge( - $this->message->getMetadata(), - [ - self::ENVELOPE_STACK_KEY => array_merge( - $this->message->getMetadata()[self::ENVELOPE_STACK_KEY] ?? [], - [self::class], - ), - ], - $this->getEnvelopeMetadata(), - ); - } - - public function getEnvelopeMetadata(): array - { - return []; - } -} diff --git a/src/Message/IdEnvelope.php b/src/Message/IdEnvelope.php index bbf0d67f..f00daf2d 100644 --- a/src/Message/IdEnvelope.php +++ b/src/Message/IdEnvelope.php @@ -7,16 +7,15 @@ /** * ID envelope allows to identify a message. */ -final class IdEnvelope implements EnvelopeInterface +final class IdEnvelope extends AbstractEnvelope { - use EnvelopeTrait; - public const MESSAGE_ID_KEY = 'yii-message-id'; public function __construct( - private MessageInterface $message, - private string|int|null $id = null, + MessageInterface $message, + private readonly string|int|null $id = null, ) { + parent::__construct($message); } public static function fromMessage(MessageInterface $message): self @@ -24,17 +23,12 @@ public static function fromMessage(MessageInterface $message): self return new self($message, $message->getMetadata()[self::MESSAGE_ID_KEY] ?? null); } - public function setId(string|int|null $id): void - { - $this->id = $id; - } - public function getId(): string|int|null { - return $this->id ?? $this->message->getMetadata()[self::MESSAGE_ID_KEY] ?? null; + return $this->id ?? $this->metadata[self::MESSAGE_ID_KEY] ?? null; } - private function getEnvelopeMetadata(): array + protected function getEnvelopeMetadata(): array { return [self::MESSAGE_ID_KEY => $this->getId()]; } diff --git a/src/Middleware/FailureHandling/FailureEnvelope.php b/src/Middleware/FailureHandling/FailureEnvelope.php index 0f6a62e9..2a81b010 100644 --- a/src/Middleware/FailureHandling/FailureEnvelope.php +++ b/src/Middleware/FailureHandling/FailureEnvelope.php @@ -4,20 +4,20 @@ namespace Yiisoft\Queue\Middleware\FailureHandling; +use Yiisoft\Arrays\ArrayHelper; use Yiisoft\Queue\Message\EnvelopeInterface; -use Yiisoft\Queue\Message\EnvelopeTrait; +use Yiisoft\Queue\Message\AbstractEnvelope; use Yiisoft\Queue\Message\MessageInterface; -final class FailureEnvelope implements EnvelopeInterface +final class FailureEnvelope extends AbstractEnvelope { - use EnvelopeTrait; - public const FAILURE_META_KEY = 'failure-meta'; public function __construct( - private MessageInterface $message, - private array $meta = [], + MessageInterface $message, + private readonly array $failureMeta = [], ) { + parent::__construct($message); } public static function fromMessage(MessageInterface $message): self @@ -25,11 +25,8 @@ public static function fromMessage(MessageInterface $message): self return new self($message, $message->getMetadata()[self::FAILURE_META_KEY] ?? []); } - public function getMetadata(): array + protected function getEnvelopeMetadata(): array { - $meta = $this->message->getMetadata(); - $meta[self::FAILURE_META_KEY] = array_merge($meta[self::FAILURE_META_KEY] ?? [], $this->meta); - - return $meta; + return [self::FAILURE_META_KEY => ArrayHelper::merge($this->metadata[self::FAILURE_META_KEY], $this->failureMeta)]; } } diff --git a/tests/Unit/EnvelopeTest.php b/tests/Unit/EnvelopeTest.php index d7e4650e..12b26a14 100644 --- a/tests/Unit/EnvelopeTest.php +++ b/tests/Unit/EnvelopeTest.php @@ -39,11 +39,7 @@ public function testEnvelopeDuplicates(): void $stack = $message->getMetadata()[EnvelopeInterface::ENVELOPE_STACK_KEY]; $this->assertIsArray($stack); - $this->assertEquals([ - IdEnvelope::class, - IdEnvelope::class, - IdEnvelope::class, - ], $stack); + $this->assertEquals([IdEnvelope::class], $stack); $this->assertEquals('test-id-3', $message->getMetadata()[IdEnvelope::MESSAGE_ID_KEY]); } diff --git a/tests/Unit/Middleware/FailureHandling/Implementation/SendAgainMiddlewareTest.php b/tests/Unit/Middleware/FailureHandling/Implementation/SendAgainMiddlewareTest.php index 665c6bea..5af29c58 100644 --- a/tests/Unit/Middleware/FailureHandling/Implementation/SendAgainMiddlewareTest.php +++ b/tests/Unit/Middleware/FailureHandling/Implementation/SendAgainMiddlewareTest.php @@ -31,7 +31,7 @@ class SendAgainMiddlewareTest extends TestCase public static function queueSendingStrategyProvider(): array { return [ - /*[ + [ SendAgainMiddleware::class, true, [], @@ -42,7 +42,7 @@ public static function queueSendingStrategyProvider(): array true, [SendAgainMiddleware::META_KEY_RESEND . '-' => 1], [SendAgainMiddleware::META_KEY_RESEND . '-' => 2], - ],*/ + ], [ SendAgainMiddleware::class, false, @@ -151,9 +151,6 @@ public function testQueueSendingStrategies( $this->expectExceptionMessage('testException'); } - $metaInitial = [FailureEnvelope::FAILURE_META_KEY => $metaInitial]; - $metaResult = [FailureEnvelope::FAILURE_META_KEY => $metaResult]; - $handler = $this->getHandler($metaResult, $suites); $queue = $this->getPreparedQueue($metaResult, $suites); @@ -162,7 +159,7 @@ public function testQueueSendingStrategies( new Message( 'test', null, - $metaInitial + [FailureEnvelope::FAILURE_META_KEY => $metaInitial], ), new Exception('testException'), $queue @@ -194,7 +191,7 @@ private function getHandler(array $metaResult, bool $suites): MessageFailureHand $pipelineAssertion = static function (FailureHandlingRequest $request) use ( $metaResult ): FailureHandlingRequest { - Assert::assertEquals($metaResult, $request->getMessage()->getMetadata()); + Assert::assertEquals($metaResult, $request->getMessage()->getMetadata()[FailureEnvelope::FAILURE_META_KEY] ?? []); throw $request->getException(); }; @@ -209,7 +206,7 @@ private function getHandler(array $metaResult, bool $suites): MessageFailureHand private function getPreparedQueue(array $metaResult, bool $suites): QueueInterface { $queueAssertion = static function (MessageInterface $message) use ($metaResult): MessageInterface { - Assert::assertEquals($metaResult, $message->getMetadata()); + Assert::assertEquals($metaResult, $message->getMetadata()[FailureEnvelope::FAILURE_META_KEY] ?? []); return $message; }; From a8564c164caacf59d9c29862dc5f4daf30fe5368 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 20 Sep 2024 13:04:47 +0000 Subject: [PATCH 02/17] Apply fixes from StyleCI --- src/Middleware/FailureHandling/FailureEnvelope.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Middleware/FailureHandling/FailureEnvelope.php b/src/Middleware/FailureHandling/FailureEnvelope.php index 2a81b010..4ccaf0f4 100644 --- a/src/Middleware/FailureHandling/FailureEnvelope.php +++ b/src/Middleware/FailureHandling/FailureEnvelope.php @@ -5,7 +5,6 @@ namespace Yiisoft\Queue\Middleware\FailureHandling; use Yiisoft\Arrays\ArrayHelper; -use Yiisoft\Queue\Message\EnvelopeInterface; use Yiisoft\Queue\Message\AbstractEnvelope; use Yiisoft\Queue\Message\MessageInterface; From 02f25346d718f529221540c31829f318d29da074 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Fri, 20 Sep 2024 18:34:49 +0500 Subject: [PATCH 03/17] Simplify abstract envelope --- src/Message/AbstractEnvelope.php | 15 ++++++++++----- src/Message/JsonMessageSerializer.php | 21 ++++++++++++--------- src/Message/Message.php | 10 +--------- src/Message/MessageInterface.php | 6 ------ 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/Message/AbstractEnvelope.php b/src/Message/AbstractEnvelope.php index ce5d63e4..1ff25073 100644 --- a/src/Message/AbstractEnvelope.php +++ b/src/Message/AbstractEnvelope.php @@ -13,16 +13,21 @@ abstract class AbstractEnvelope implements EnvelopeInterface public function __construct(MessageInterface $message) { - $this->message = $message instanceof EnvelopeInterface ? $message->getMessage() : $message; $this->metadata = $message->getMetadata(); + $envelopes = [static::class]; + while ($message instanceof EnvelopeInterface) { + if ($message::class !== static::class) { + $envelopes = [$message::class]; + } + + $message = $message->getMessage(); + } + $this->message = $message; if (is_array($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY])) { $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = array_merge( [static::class], - array_filter( - $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY], - static fn(string $class) => $class !== static::class, - ) + $envelopes, ); } else { $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = [static::class]; diff --git a/src/Message/JsonMessageSerializer.php b/src/Message/JsonMessageSerializer.php index 81a6220c..371ff421 100644 --- a/src/Message/JsonMessageSerializer.php +++ b/src/Message/JsonMessageSerializer.php @@ -39,21 +39,24 @@ public function unserialize(string $value): MessageInterface throw new InvalidArgumentException('Metadata must be array. Got ' . get_debug_type($meta) . '.'); } + $envelopes = []; + if (isset($meta[EnvelopeInterface::ENVELOPE_STACK_KEY]) && is_array($meta[EnvelopeInterface::ENVELOPE_STACK_KEY])) { + $envelopes = $meta[EnvelopeInterface::ENVELOPE_STACK_KEY]; + } + $meta[EnvelopeInterface::ENVELOPE_STACK_KEY] = []; + // TODO: will be removed later $message = new Message($payload['name'] ?? '$name', $payload['data'] ?? null, $meta); - if (isset($meta[EnvelopeInterface::ENVELOPE_STACK_KEY]) && is_array($meta[EnvelopeInterface::ENVELOPE_STACK_KEY])) { - $message = $message->withMetadata( - array_merge($message->getMetadata(), [EnvelopeInterface::ENVELOPE_STACK_KEY => []]), - ); - foreach ($meta[EnvelopeInterface::ENVELOPE_STACK_KEY] as $envelope) { - if (is_string($envelope) && class_exists($envelope) && is_subclass_of($envelope, EnvelopeInterface::class)) { - $message = $envelope::fromMessage($message); - } + foreach ($envelopes as $envelope) { + if (is_string($envelope) && class_exists($envelope) && is_subclass_of( + $envelope, + EnvelopeInterface::class + )) { + $message = $envelope::fromMessage($message); } } - return $message; } } diff --git a/src/Message/Message.php b/src/Message/Message.php index a414ffb0..2945cc72 100644 --- a/src/Message/Message.php +++ b/src/Message/Message.php @@ -7,9 +7,9 @@ final class Message implements MessageInterface { /** + * @param string $handlerName A name of a handler which should handle this message * @param mixed $data Message data, encodable by a queue adapter * @param array $metadata Message metadata, encodable by a queue adapter - * @param string|null $id Message id */ public function __construct( private string $handlerName, @@ -32,12 +32,4 @@ public function getMetadata(): array { return $this->metadata; } - - public function withMetadata(array $metadata): self - { - $instance = clone $this; - $instance->metadata = $metadata; - - return $instance; - } } diff --git a/src/Message/MessageInterface.php b/src/Message/MessageInterface.php index c65f32fd..58fc8cf8 100644 --- a/src/Message/MessageInterface.php +++ b/src/Message/MessageInterface.php @@ -8,22 +8,16 @@ interface MessageInterface { /** * Returns handler name. - * - * @return string */ public function getHandlerName(): string; /** * Returns payload data. - * - * @return mixed */ public function getData(): mixed; /** * Returns message metadata: timings, attempts count, metrics, etc. - * - * @return array */ public function getMetadata(): array; } From 2bb91add86f21cd3aaad6af21daf2cf73d234e51 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Fri, 20 Sep 2024 18:42:38 +0500 Subject: [PATCH 04/17] Fix bug and test --- src/Message/AbstractEnvelope.php | 5 ++++- tests/Unit/Message/JsonMessageSerializerTest.php | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Message/AbstractEnvelope.php b/src/Message/AbstractEnvelope.php index 1ff25073..f8482e1c 100644 --- a/src/Message/AbstractEnvelope.php +++ b/src/Message/AbstractEnvelope.php @@ -26,8 +26,11 @@ public function __construct(MessageInterface $message) if (is_array($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY])) { $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = array_merge( - [static::class], $envelopes, + array_filter( + $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY], + static fn (string $envelope): bool => !in_array($envelope, $envelopes), + ), ); } else { $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = [static::class]; diff --git a/tests/Unit/Message/JsonMessageSerializerTest.php b/tests/Unit/Message/JsonMessageSerializerTest.php index 776a9835..cf710282 100644 --- a/tests/Unit/Message/JsonMessageSerializerTest.php +++ b/tests/Unit/Message/JsonMessageSerializerTest.php @@ -66,7 +66,7 @@ public function testUnserializeFromData(): void $this->assertInstanceOf(MessageInterface::class, $message); $this->assertEquals($payload['data'], $message->getData()); - $this->assertEquals([], $message->getMetadata()); + $this->assertEquals([EnvelopeInterface::ENVELOPE_STACK_KEY => []], $message->getMetadata()); } public function testUnserializeWithMetadata(): void @@ -78,7 +78,10 @@ public function testUnserializeWithMetadata(): void $this->assertInstanceOf(MessageInterface::class, $message); $this->assertEquals($payload['data'], $message->getData()); - $this->assertEquals(['int' => 1, 'str' => 'string', 'bool' => true], $message->getMetadata()); + $this->assertEquals( + ['int' => 1, 'str' => 'string', 'bool' => true, EnvelopeInterface::ENVELOPE_STACK_KEY => []], + $message->getMetadata() + ); } public function testUnserializeEnvelopeStack(): void From 45c7c576b3ba1b2f8a68cbe101e00ddbe6d934b9 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 20 Sep 2024 13:43:56 +0000 Subject: [PATCH 05/17] Apply fixes from StyleCI --- src/Message/JsonMessageSerializer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Message/JsonMessageSerializer.php b/src/Message/JsonMessageSerializer.php index 371ff421..f1d60137 100644 --- a/src/Message/JsonMessageSerializer.php +++ b/src/Message/JsonMessageSerializer.php @@ -50,9 +50,9 @@ public function unserialize(string $value): MessageInterface foreach ($envelopes as $envelope) { if (is_string($envelope) && class_exists($envelope) && is_subclass_of( - $envelope, - EnvelopeInterface::class - )) { + $envelope, + EnvelopeInterface::class + )) { $message = $envelope::fromMessage($message); } } From 9438b871fc83587f566806d1ecb5f955f5cdf6bd Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Fri, 20 Sep 2024 18:44:42 +0500 Subject: [PATCH 06/17] Require yiisoft/arrays package --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index c59f8ca9..ff972a13 100644 --- a/composer.json +++ b/composer.json @@ -40,6 +40,7 @@ "psr/container": "^1.0|^2.0", "psr/log": "^2.0|^3.0", "symfony/console": "^5.4|^6.0", + "yiisoft/arrays": "^3.1", "yiisoft/definitions": "^1.0|^2.0|^3.0", "yiisoft/friendly-exception": "^1.0", "yiisoft/injector": "^1.0" From 3afb619181c65a029f1ace7be9725707ce7147ba Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Fri, 20 Sep 2024 18:48:00 +0500 Subject: [PATCH 07/17] Fix warnings --- src/Message/AbstractEnvelope.php | 2 +- src/Middleware/FailureHandling/FailureEnvelope.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/AbstractEnvelope.php b/src/Message/AbstractEnvelope.php index f8482e1c..66b44e54 100644 --- a/src/Message/AbstractEnvelope.php +++ b/src/Message/AbstractEnvelope.php @@ -24,7 +24,7 @@ public function __construct(MessageInterface $message) } $this->message = $message; - if (is_array($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY])) { + if (isset($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY]) && is_array($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY])) { $this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = array_merge( $envelopes, array_filter( diff --git a/src/Middleware/FailureHandling/FailureEnvelope.php b/src/Middleware/FailureHandling/FailureEnvelope.php index 4ccaf0f4..97e194d6 100644 --- a/src/Middleware/FailureHandling/FailureEnvelope.php +++ b/src/Middleware/FailureHandling/FailureEnvelope.php @@ -26,6 +26,6 @@ public static function fromMessage(MessageInterface $message): self protected function getEnvelopeMetadata(): array { - return [self::FAILURE_META_KEY => ArrayHelper::merge($this->metadata[self::FAILURE_META_KEY], $this->failureMeta)]; + return [self::FAILURE_META_KEY => ArrayHelper::merge($this->metadata[self::FAILURE_META_KEY] ?? [], $this->failureMeta)]; } } From 75d600aaeb9460daa1d08bcb49500cb15b96014c Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Sun, 13 Oct 2024 23:01:13 +0500 Subject: [PATCH 08/17] Use new PhpBench action version --- .github/workflows/bechmark.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bechmark.yml b/.github/workflows/bechmark.yml index 36190113..91148890 100644 --- a/.github/workflows/bechmark.yml +++ b/.github/workflows/bechmark.yml @@ -25,9 +25,12 @@ name: bechmark jobs: phpbench: - uses: yiisoft/actions/.github/workflows/phpbench.yml@master + uses: yiisoft/actions/.github/workflows/phpbench.yml@phpbench-improvement with: os: >- ['ubuntu-latest', 'windows-latest'] php: >- - ['8.1'] + ['8.1', '8.2', '8.3'] + ref-name: master + secrets: + token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} From 9028b65452cd8ee32c05789cf6d22755f4d65a6e Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Mon, 4 Nov 2024 15:23:07 +0500 Subject: [PATCH 09/17] Start less checks for tests --- .github/workflows/bechmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bechmark.yml b/.github/workflows/bechmark.yml index 91148890..8974f227 100644 --- a/.github/workflows/bechmark.yml +++ b/.github/workflows/bechmark.yml @@ -30,7 +30,7 @@ jobs: os: >- ['ubuntu-latest', 'windows-latest'] php: >- - ['8.1', '8.2', '8.3'] + ['8.1'] ref-name: master secrets: token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} From 5beb769262d7ae7a46b0a3a50c3801f68ec64564 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Mon, 4 Nov 2024 19:38:22 +0500 Subject: [PATCH 10/17] more checks again --- .github/workflows/bechmark.yml | 2 +- phpbench.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bechmark.yml b/.github/workflows/bechmark.yml index 8974f227..51c1b018 100644 --- a/.github/workflows/bechmark.yml +++ b/.github/workflows/bechmark.yml @@ -30,7 +30,7 @@ jobs: os: >- ['ubuntu-latest', 'windows-latest'] php: >- - ['8.1'] + ['8.1', '8.2', '8.3', '8.4'] ref-name: master secrets: token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} diff --git a/phpbench.json b/phpbench.json index 04436028..9c76ae2e 100644 --- a/phpbench.json +++ b/phpbench.json @@ -4,5 +4,6 @@ "runner.path": "tests/Benchmark", "runner.revs": 100000, "runner.iterations": 5, - "runner.warmup": 5 + "runner.warmup": 5, + "runner.retry_threshold": 5 } From bf3d40a191151ce480b7f2cb9db93c0d15bd7987 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Sun, 10 Nov 2024 22:22:13 +0500 Subject: [PATCH 11/17] Remove token from bench workflow --- .github/workflows/bechmark.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/bechmark.yml b/.github/workflows/bechmark.yml index 51c1b018..997aa7f0 100644 --- a/.github/workflows/bechmark.yml +++ b/.github/workflows/bechmark.yml @@ -32,5 +32,3 @@ jobs: php: >- ['8.1', '8.2', '8.3', '8.4'] ref-name: master - secrets: - token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} From 45293ba2a5e75681e7e611bf922ba9784def52e5 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Mon, 11 Nov 2024 23:02:33 +0300 Subject: [PATCH 12/17] Update src/Message/Message.php --- src/Message/Message.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/Message.php b/src/Message/Message.php index 2945cc72..8e580514 100644 --- a/src/Message/Message.php +++ b/src/Message/Message.php @@ -7,7 +7,7 @@ final class Message implements MessageInterface { /** - * @param string $handlerName A name of a handler which should handle this message + * @param string $handlerName A name of a handler which should handle this message. * @param mixed $data Message data, encodable by a queue adapter * @param array $metadata Message metadata, encodable by a queue adapter */ From f43c94af4d7bad697b169313d19e2741f053ae47 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Sun, 17 Nov 2024 17:45:21 +0500 Subject: [PATCH 13/17] Fix PhpBench action version --- .github/workflows/bechmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bechmark.yml b/.github/workflows/bechmark.yml index 1ac824ec..8a6f17c5 100644 --- a/.github/workflows/bechmark.yml +++ b/.github/workflows/bechmark.yml @@ -25,7 +25,7 @@ name: bechmark jobs: phpbench: - uses: yiisoft/actions/.github/workflows/phpbench.yml@phpbench-improvement + uses: yiisoft/actions/.github/workflows/phpbench.yml with: os: >- ['ubuntu-latest', 'windows-latest'] From 784a82647bc2398007b8c742e7f93312fbae44a5 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Sun, 17 Nov 2024 17:50:47 +0500 Subject: [PATCH 14/17] Fix PhpBench action version --- .github/workflows/bechmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bechmark.yml b/.github/workflows/bechmark.yml index 8a6f17c5..a47f6a6c 100644 --- a/.github/workflows/bechmark.yml +++ b/.github/workflows/bechmark.yml @@ -25,7 +25,7 @@ name: bechmark jobs: phpbench: - uses: yiisoft/actions/.github/workflows/phpbench.yml + uses: yiisoft/actions/.github/workflows/phpbench.yml@master with: os: >- ['ubuntu-latest', 'windows-latest'] From 0ea2fdf6b10f6af616e4f95f192516f6ab1cba00 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Sun, 17 Nov 2024 17:55:49 +0500 Subject: [PATCH 15/17] Remove PHP 8.4 from PhpBench action --- .github/workflows/bechmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bechmark.yml b/.github/workflows/bechmark.yml index a47f6a6c..2751bdf5 100644 --- a/.github/workflows/bechmark.yml +++ b/.github/workflows/bechmark.yml @@ -30,4 +30,4 @@ jobs: os: >- ['ubuntu-latest', 'windows-latest'] php: >- - ['8.1', '8.2', '8.3', '8.4'] + ['8.1', '8.2', '8.3'] From d884b8dbf2cf11290ca770aa2d32d7c6cdc4606a Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Sun, 24 Nov 2024 20:29:04 +0500 Subject: [PATCH 16/17] Fix merge error --- src/Message/AbstractEnvelope.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Message/AbstractEnvelope.php b/src/Message/AbstractEnvelope.php index 66b44e54..a84c96bb 100644 --- a/src/Message/AbstractEnvelope.php +++ b/src/Message/AbstractEnvelope.php @@ -60,6 +60,11 @@ public function getMetadata(): array ); } + public static function fromData(string $handlerName, mixed $data, array $metadata = []): MessageInterface + { + return static::fromMessage(Message::fromData($handlerName, $data, $metadata)); + } + /** * Metadata of the envelope * From 7a4fc68b2eaa68b848ad868f536b14ae19e9c379 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Sun, 24 Nov 2024 20:29:10 +0500 Subject: [PATCH 17/17] Fix test --- tests/Unit/QueueTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index 7a477e66..d140bcd1 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -130,6 +130,10 @@ public function testAdapterNotConfiguredExceptionForRun(): void public function testRunWithSignalLoop(): void { + if (!extension_loaded('pcntl')) { + self::markTestSkipped('PCNTL support required'); + } + $this->loop = new SignalLoop(); $queue = $this ->getQueue()