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

Add support for ack, nack, and requeue methods #66

Merged
merged 5 commits into from
Jun 24, 2024

Conversation

msmakouz
Copy link
Member

@msmakouz msmakouz commented Jun 24, 2024

Q A
Bugfix?
Breaks BC?
New feature? ✔️
Issues roadrunner-server/roadrunner#1941

Added support for ack, nack, and requeue methods.

Closes: roadrunner-server/roadrunner#1941

@msmakouz msmakouz added the enhancement New feature or request label Jun 24, 2024
@msmakouz msmakouz requested review from wolfy-j and rustatian June 24, 2024 13:02
@msmakouz msmakouz self-assigned this Jun 24, 2024
Copy link

coderabbitai bot commented Jun 24, 2024

Walkthrough

The recent updates to the Consumer class and related entities introduce enhanced methods for task processing, primarily focusing on acknowledgment (ack), negative acknowledgment (nack with redelivery), and requeueing. These changes aim to preserve message order in the RabbitMQ queue, addressing issues where messages were requeued at the end rather than their original position.

Changes

File Change Summary
README.md Documented new and modified methods in the Consumer class and associated behaviors.
src/Task/ReceivedTask.php Deprecated complete and fail methods; added ack, nack, and requeue methods.
src/Task/ReceivedTaskInterface.php Updated interface to include new methods and deprecation warnings.
src/Task/Type.php Deprecated old constants and introduced ACK, NACK, REQUEUE constants.
tests/Unit/Task/ReceivedTaskTest.php Added new test methods for ack, nack, and `requeue; enhanced data handling with DataProvider.
psalm.xml Added a new rule to handle missing type declarations for class constants.

Sequence Diagram(s)

sequenceDiagram
    participant Consumer
    participant RabbitMQ
    Consumer->>RabbitMQ: Process message
    RabbitMQ->>Consumer: Processing Successful (ack)
    Consumer-->>RabbitMQ: ack()

    Consumer->>RabbitMQ: Process message
    RabbitMQ-->>Consumer: Processing Failed (nack/redeliver)
    Consumer-->>RabbitMQ: nack(redelivery: true)

    Consumer->>RabbitMQ: Process message
    RabbitMQ->>Consumer: Error Occurred
    Consumer-->>RabbitMQ: requeue(with headers and delay)
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Preserve message order after requeuing ( #1941)
Introduce ack, nack, requeue methods ( #1941)
Deprecate complete and fail methods appropriately ( #1941)
Update constants to align with new method names ( #1941)
Ensure new methods are thoroughly tested ( #1941)

Poem

In the code, new methods lie,
To handle tasks once they fly.
Ack for those who do succeed,
Nack for errors that impede.
And in the queue where order's true,
Requeue will now empower you.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
README.md (1)

Line range hint 4-4: Add alternate text to images for accessibility.

Images in lines 4 and 17 lack alt text, which is important for accessibility and SEO.

- <img align="center" src="https://github.com/roadrunner-server/.github/assets/8040338/040fb694-1dd3-4865-9d29-8e0748c2c8b8">
+ <img align="center" src="https://github.com/roadrunner-server/.github/assets/8040338/040fb694-1dd3-4865-9d29-8e0748c2c8b8" alt="RoadRunner Jobs Plugin Logo">
- <img src="https://user-images.githubusercontent.com/773481/220979012-e67b74b5-3db1-41b7-bdb0-8a042587dedc.jpg" alt="try Spiral Framework" />
+ <img src="https://user-images.githubusercontent.com/773481/220979012-e67b74b5-3db1-41b7-bdb0-8a042587dedc.jpg" alt="Spiral Framework Advertisement" />

Also applies to: 17-17

Tools
LanguageTool

[style] ~118-~118: The phrase ‘have the ability to’ might be wordy. Consider using “can”. (HAS_THE_ABILITY_TO)
Context: ...; ``` The nack and `requeue` methods have the ability to specify a delay for requeuing the t...


[style] ~118-~118: Consider a more expressive alternative. (DO_ACHIEVE)
Context: ... a delay for requeuing the task. To do this, call the withDelay method and ...

Markdownlint

103-103: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


118-118: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0013e1e and 3204a58.

Files selected for processing (5)
  • README.md (2 hunks)
  • src/Task/ReceivedTask.php (2 hunks)
  • src/Task/ReceivedTaskInterface.php (2 hunks)
  • src/Task/Type.php (1 hunks)
  • tests/Unit/Task/ReceivedTaskTest.php (4 hunks)
Additional context used
LanguageTool
README.md

[style] ~10-~10: Using many exclamation marks might seem excessive (in this case: 6 exclamation marks for a text that’s 2916 characters long) (EN_EXCESSIVE_EXCLAMATION)
Context: ...st.org/packages/spiral/roadrunner-jobs) Latest Stable Version phpunit psalm Codecov Total Downloads [![StyleCI](https://github.styleci.io/repo...


[uncategorized] ~37-~37: Possible missing comma found. (AI_HYDRA_LEO_MISSING_COMMA)
Context: ...endor/bin/rr get ``` ## Configuration First you need to add at least one jobs adapt...


[style] ~118-~118: The phrase ‘have the ability to’ might be wordy. Consider using “can”. (HAS_THE_ABILITY_TO)
Context: ...; ``` The nack and `requeue` methods have the ability to specify a delay for requeuing the t...


[style] ~118-~118: Consider a more expressive alternative. (DO_ACHIEVE)
Context: ... a delay for requeuing the task. To do this, call the withDelay method and ...

Markdownlint
README.md

103-103: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


118-118: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


4-4: null (MD045, no-alt-text)
Images should have alternate text (alt text)


17-17: null (MD045, no-alt-text)
Images should have alternate text (alt text)

Additional comments not posted (18)
src/Task/Type.php (5)

14-14: Deprecation notice is clear and well-documented.

The deprecation comment for SUCCESS clearly indicates the version and the alternative to use, which is a good practice for maintainability.


20-20: Deprecation notice is clear and well-documented.

The deprecation comment for ERROR is clear about the version and provides alternatives (NACK or REQUEUE), which helps in transitioning to the new constants.


27-27: New constant ACK introduced correctly.

The introduction of the ACK constant is aligned with the PR objectives to handle task acknowledgments more explicitly.


32-32: New constant NACK introduced correctly.

The NACK constant provides a clear way to handle negative acknowledgments, which is crucial for error handling in task processing.


37-37: New constant REQUEUE introduced correctly.

The REQUEUE constant supports the new feature of re-queuing tasks, which is essential for maintaining message order as per the linked issue discussion.

src/Task/ReceivedTaskInterface.php (3)

12-14: New method signatures for ack, nack, and requeue are well-defined.

These methods are crucial for the new functionality introduced in the PR and are well-documented in the interface.


25-25: Deprecation of complete is well-documented.

The method complete is deprecated in favor of ack, which is aligned with the new task handling strategy.


33-33: Deprecation of fail is well-documented.

The method fail is deprecated in favor of nack and requeue, which provides more granular control over task failures.

src/Task/ReceivedTask.php (5)

91-94: Implementation of ack method is correct and concise.

The method correctly uses the new Type::ACK constant and ensures the task is marked as completed.


96-102: Implementation of nack method is detailed and handles redelivery.

The method correctly uses the Type::NACK constant and allows for optional redelivery, which is essential for robust task processing.


105-117: Implementation of requeue method is robust and flexible.

The method correctly uses the Type::REQUEUE constant and supports additional headers and delay, aligning with the PR objectives.


66-67: Deprecation of complete method is clear and directs users to the new ack method.


74-75: Deprecation of fail method is clear and directs users to the new nack and requeue methods.

README.md (1)

96-123: Documentation update is comprehensive and clear.

The updated sections clearly explain the functionality of the new ack, nack, and requeue methods, including parameters and behavior. This is crucial for users to understand how to use the new features.

Tools
LanguageTool

[style] ~118-~118: The phrase ‘have the ability to’ might be wordy. Consider using “can”. (HAS_THE_ABILITY_TO)
Context: ...; ``` The nack and `requeue` methods have the ability to specify a delay for requeuing the t...


[style] ~118-~118: Consider a more expressive alternative. (DO_ACHIEVE)
Context: ... a delay for requeuing the task. To do this, call the withDelay method and ...

Markdownlint

103-103: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


118-118: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces

tests/Unit/Task/ReceivedTaskTest.php (4)

8-8: New import added for DataProvider.

This import is necessary to utilize the #[DataProvider] attribute in the test methods, which allows for parameterized tests. This is a good practice as it enhances the test's flexibility and reusability.


83-106: Review of the testAck method.

This method tests the ack functionality of the ReceivedTask. The test is well-structured, simulating the task's completion and success without failure. The mock setup and assertions are appropriate and check the payload structure correctly. The transition from Type::SUCCESS to Type::ACK is correctly implemented in the test.


116-156: Review of the testNack method with data provider.

The method correctly uses a data provider to test various scenarios of the nack functionality. The handling of the redelivery and delay parameters is well done, and the method correctly asserts the state transitions and the response payload structure. However, ensure that the redelivery boolean is handled correctly in all cases, especially when it affects the payload structure significantly.


159-203: Review of the testRequeue method with data provider.

This method is well-implemented, testing the requeue functionality with various configurations of delays and headers. The use of a data provider enhances test coverage. The assertions on the task state and payload content are precise, ensuring that the requeue functionality is working as expected, including the handling of headers in the payload.
[APROVED]

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3204a58 and 941d799.

Files selected for processing (1)
  • src/Task/ReceivedTask.php (2 hunks)
Additional comments not posted (5)
src/Task/ReceivedTask.php (5)

65-67: Deprecation notice for complete() method is clear and well-documented.


73-75: Deprecation notice for fail() method is clear and well-documented.


91-94: Implementation of ack() method is correct and straightforward.

The method correctly uses the Type::ACK constant to respond to success. This aligns well with the PR's objective of enhancing message acknowledgment handling.


129-129: Update status check methods to include new constants.

The updates to isSuccessful() and isFails() methods to include checks for Type::ACK, Type::NACK, and Type::REQUEUE are appropriate and align with the changes in method functionality. This ensures that the task statuses are accurately reflected.

Also applies to: 134-136


108-120: Review the implementation of requeue() method.

The requeue() method correctly uses the Type::REQUEUE constant and includes handling for delayed re-queueing and header adjustments. This method is crucial for addressing the linked issue regarding message order preservation. Ensure that the headers manipulation and delay settings are explicitly tested to confirm they meet the expected behavior.

Verification successful

Verified: The testRequeue method adequately tests the delay and headers handling in the requeue method.

  • The test checks if the task is correctly updated with delay and headers.
  • It verifies that the respond method is called with the appropriate payload, including delay and headers.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if delay and headers are handled correctly in the requeue method.

# Test: Search for unit tests covering delay and header manipulation in requeue method.
rg --type php 'testRequeue'

Length of output: 165



Script:

#!/bin/bash
# Extract the implementation of the testRequeue function from the relevant file.
ast-grep --lang php --pattern 'function testRequeue($_, $_, $_, $_) { $$$ }' tests/Unit/Task/ReceivedTaskTest.php

Length of output: 222



Script:

#!/bin/bash
# Locate the testRequeue function definition and extract surrounding lines.
rg -A 20 'function testRequeue' tests/Unit/Task/ReceivedTaskTest.php

Length of output: 792



Script:

#!/bin/bash
# Extract additional lines to capture the complete implementation of the testRequeue function.
rg -A 40 'function testRequeue' tests/Unit/Task/ReceivedTaskTest.php

Length of output: 1393

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 941d799 and 4a15c40.

Files selected for processing (1)
  • psalm.xml (1 hunks)
Files skipped from review due to trivial changes (1)
  • psalm.xml

Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.25%. Comparing base (4621491) to head (5a4c061).
Report is 1 commits behind head on 4.x.

Additional details and impacted files
@@             Coverage Diff              @@
##                4.x      #66      +/-   ##
============================================
+ Coverage     86.87%   87.25%   +0.38%     
- Complexity      197      204       +7     
============================================
  Files            30       30              
  Lines           602      620      +18     
============================================
+ Hits            523      541      +18     
  Misses           79       79              

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
README.md (2)

98-100: Clarify the purpose of the methods for better understanding.

The methods ack, nack, and requeue are mentioned, but a brief explanation of each could enhance clarity for users unfamiliar with these terms.


111-113: Explain the independence of the requeue method from the queue driver.

It's valuable to highlight that the requeue method's functionality does not depend on the queue driver, which is a significant aspect of its behavior.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4a15c40 and 5a4c061.

Files selected for processing (2)
  • README.md (2 hunks)
  • src/Task/ReceivedTask.php (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/Task/ReceivedTask.php
Additional context used
LanguageTool
README.md

[style] ~10-~10: Using many exclamation marks might seem excessive (in this case: 6 exclamation marks for a text that’s 2916 characters long) (EN_EXCESSIVE_EXCLAMATION)
Context: ...st.org/packages/spiral/roadrunner-jobs) Latest Stable Version phpunit psalm Codecov Total Downloads [![StyleCI](https://github.styleci.io/repo...


[style] ~118-~118: The phrase ‘have the ability to’ might be wordy. Consider using “can”. (HAS_THE_ABILITY_TO)
Context: ...; ``` The nack and `requeue` methods have the ability to specify a delay for requeuing the t...


[style] ~118-~118: Consider a more expressive alternative. (DO_ACHIEVE)
Context: ... a delay for requeuing the task. To do this, call the withDelay method and ...

Markdownlint
README.md

103-103: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


118-118: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


4-4: null (MD045, no-alt-text)
Images should have alternate text (alt text)


17-17: null (MD045, no-alt-text)
Images should have alternate text (alt text)

Additional comments not posted (2)
README.md (2)

103-105: Clarify the redelivery parameter's behavior.

The description of the redelivery parameter's behavior could be clearer. It's important to explicitly mention that setting redelivery to true attempts to requeue the task, but this is contingent on the driver's support.

Tools
Markdownlint

103-103: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


145-147: Ensure proper error handling in the Consumer code snippet.

The catch block for handling errors in the Consumer code snippet is critical. It would be beneficial to ensure that all possible exceptions are appropriately handled and logged.

Comment on lines +118 to +119
The `nack` and `requeue` methods have the ability to specify a **delay** for requeuing the task. To do this, call
the `withDelay` method and pass the desired value before invoking the `nack` or `requeue` methods.
Copy link

Choose a reason for hiding this comment

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

Simplify language for setting delays in requeuing.

The current phrasing could be simplified for better readability and understanding.

- The `nack` and `requeue` methods have the ability to specify a **delay** for requeuing the task. To do this, call 
- the `withDelay` method and pass the desired value before invoking the `nack` or `requeue` methods.
+ The `nack` and `requeue` methods can set a **delay** for requeuing tasks by calling `withDelay` with the desired value before invocation.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
The `nack` and `requeue` methods have the ability to specify a **delay** for requeuing the task. To do this, call
the `withDelay` method and pass the desired value before invoking the `nack` or `requeue` methods.
The `nack` and `requeue` methods can set a **delay** for requeuing tasks by calling `withDelay` with the desired value before invocation.
Tools
LanguageTool

[style] ~118-~118: The phrase ‘have the ability to’ might be wordy. Consider using “can”. (HAS_THE_ABILITY_TO)
Context: ...; ``` The nack and `requeue` methods have the ability to specify a delay for requeuing the t...


[style] ~118-~118: Consider a more expressive alternative. (DO_ACHIEVE)
Context: ... a delay for requeuing the task. To do this, call the withDelay method and ...

Markdownlint

118-118: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces

@msmakouz msmakouz merged commit ab1e4ff into 4.x Jun 24, 2024
9 checks passed
@msmakouz msmakouz deleted the feature/ack-nack-requeue branch June 24, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[💡 FEATURE REQUEST]: preserve message publication order after re-queuing
2 participants