Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor handlers #182

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Refactor handlers #182

wants to merge 11 commits into from

Conversation

xepozz
Copy link
Member

@xepozz xepozz commented Dec 25, 2023

Q A
Is bugfix?
New feature?
Breaks BC? ✔️

Drop support pre-configured handlers, make it compatible with validator/hydrator handlers way

The old way:

  1. Add handler name => handler definition mapping to config/params
  2. Add handler name to the message getHandlerName method

The new way:

  1. Create a class that implements the new MessageHandlerInterface
  2. Add the class name to the message getHandler method

The new way is similar with validator's or hydrator's way.

Copy link

what-the-diff bot commented Dec 25, 2023

PR Summary

  • Refactoring Message Handling
    • The PR changes the terminology from handlerName to handler in different classes and files for consistency. It affects the classes: Message, Queue, TestMiddleware, and various test files. This also includes renaming the method getHandlerName method to getHandler in the MessageInterface interface.
  • Alteration in FileDownloader and Worker Classes
    • The handle method in the FileDownloader class will now output a MessageInterface object. Also, the same method in the Worker class will now throw a RuntimeException if the handler name is not found, increasing error handling.
  • Removing handlers Property and QueueWorker Class
    • The handlers property has been removed from the Worker class constructor, and the QueueWorker class has been removed from di.php file, simplifying the structure.
  • Addition of MessageHandlerInterface Interface
    • A new MessageHandlerInterface interface was added, which is implemented by the FakeHandler class, promoting code reusability and abstraction.
  • Modification in MessageConsumingTest and MiddlewareTest Classes
    • MessageConsumingTest and MiddlewareTest now use different classes as the handler for messages (StackMessageHandler and NullMessageHandler respectively), which promotes diverse handling processes.
  • Adding New Classes
    • Three new classes: ExceptionMessageHandler, NullMessageHandler, and StackMessageHandler were added, enhancing the system's capabilities to handle diverse message types.
  • Removal of getMessageHandlers Method
    • The getMessageHandlers method was removed from TestCase class, reducing redundancy in the codebase.
  • Additional Changes in Multiple Test Methods
    • Several test methods in files like MiddlewareDispatcherTest.php, QueueTest.php, SynchronousAdapterTest.php, and WorkerTest.php were modified, promoting better and diverse testing with modified handler values.

Minor changes and adjustments were made throughout the codebase to align with these changes. Please ask if further clarification is needed.

Copy link

codecov bot commented Dec 25, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (5339df8) 83.98% compared to head (725ef84) 83.15%.

Files Patch % Lines
src/Worker/Worker.php 36.36% 7 Missing ⚠️
config/di.php 0.00% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #182      +/-   ##
============================================
- Coverage     83.98%   83.15%   -0.84%     
+ Complexity      359      345      -14     
============================================
  Files            46       46              
  Lines          1049     1021      -28     
============================================
- Hits            881      849      -32     
- Misses          168      172       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xepozz xepozz added the status:code review The pull request needs review. label Dec 25, 2023
Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

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

The idea was that handler is not a PHP class string because worker could be implemented in non-PHP.

@xepozz
Copy link
Member Author

xepozz commented Dec 26, 2023

The idea was that handler is not a PHP class string because worker could be implemented in non-PHP.

Already discussed in the internal chat.

There're should be routing outside a message to be able to work with different services across the one queue.

@samdark
Copy link
Member

samdark commented Dec 26, 2023

With queue backends such as Redis, there's no external routing.

@samdark
Copy link
Member

samdark commented Dec 26, 2023

Discussed internally. It makes sense if we'll introduce "message type decorator" and "message-based handlers" for messages in a separate PR.

src/Queue.php Show resolved Hide resolved
xepozz and others added 5 commits January 13, 2024 22:02
# Conflicts:
#	README.md
#	config/di.php
#	config/params.php
#	src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php
#	src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php
#	src/Queue.php
#	src/Worker/Worker.php
#	tests/App/FakeHandler.php
#	tests/Integration/MessageConsumingTest.php
#	tests/Integration/MiddlewareTest.php
#	tests/TestCase.php
#	tests/Unit/QueueTest.php
#	tests/Unit/SynchronousAdapterTest.php
#	tests/Unit/WorkerTest.php
# Conflicts:
#	config/params.php
#	tests/App/FakeHandler.php
#	tests/TestCase.php
#	tests/Unit/WorkerTest.php
@@ -10,8 +10,9 @@ interface MessageInterface
* Returns handler name.
*
* @return string
* @psalm-return class-string<MessageHandlerInterface>
Copy link
Member

Choose a reason for hiding this comment

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

Any string can be here (for example, ID for container), but class string only.

@@ -89,21 +92,21 @@ class FileDownloader
$this->absolutePath = $absolutePath;
}

public function handle(\Yiisoft\Queue\Message\MessageInterface $downloadMessage): void
public function handle(\Yiisoft\Queue\Message\MessageInterface $downloadMessage): MessageInterface
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function handle(\Yiisoft\Queue\Message\MessageInterface $downloadMessage): MessageInterface
public function handle(\Yiisoft\Queue\Message\MessageInterface $downloadMessage): void

Comment on lines +100 to +101

return $message;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return $message;

{
return $this->message->getHandlerName();
return $this->message->getHandler();
Copy link
Member

Choose a reason for hiding this comment

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

There may be a problem here, when handler support only original message and don't support envelope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:code review The pull request needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants