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

feature: JOBS v4 API #40

Merged
merged 3 commits into from
Jul 3, 2024
Merged

feature: JOBS v4 API #40

merged 3 commits into from
Jul 3, 2024

Conversation

rustatian
Copy link
Member

@rustatian rustatian commented Jul 3, 2024

Reason for This PR

Description of Changes

  • Better handling Ack/Nack.
  • Events to restart the pipeline.
  • JOBS API v4.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • New Features

    • Added new configuration keys for dead-letter topics and priority in pub/sub jobs settings.
    • Enhanced event handling capabilities in pub/sub driver.
  • Bug Fixes

    • Improved error handling and pipeline restart logic to enhance reliability.
  • Chores

    • Updated linter and various dependencies to newer versions.
    • Revised .gitignore entries for better project management.
  • Tests

    • Enhanced test configurations and assertions for log messages.
    • Updated task handling logic in PHP test files for better error management.

@rustatian rustatian added the enhancement New feature or request label Jul 3, 2024
@rustatian rustatian requested a review from wolfy-j July 3, 2024 15:11
@rustatian rustatian self-assigned this Jul 3, 2024
@rustatian rustatian marked this pull request as draft July 3, 2024 15:12
Copy link

coderabbitai bot commented Jul 3, 2024

Warning

Rate limit exceeded

@rustatian has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 20 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between fdbb9d0 and 2c4b860.

Walkthrough

The recent updates involve version changes in configuration files, additions and modifications to Go and PHP files to improve task handling and error management, and adjustments to linter settings. These changes aim to enhance the robustness and maintainability of the project, ensuring compatibility with newer dependencies and refining the task processing logic.

Changes

File Summary
.github/workflows/linters.yml Updated linter version from v1.58 to v1.59.
.gitignore Added **/composer.lock pattern, removed vendor/ entry.
.golangci.yml Removed the dupl linter.
go.mod Updated google-pub-sub module to v5, other dependencies updated
plugin.go Modified imports to include new package versions, updated DriverFromConfig and DriverFromPipeline.
pubsubjobs/config.go Added new config keys (deadLetterTopic, maxDeliveryAttempts, priority), updated struct fields.
pubsubjobs/driver.go Enhanced Driver struct functionalities, reworked topic and subscription management, added dead-letter topic support.
pubsubjobs/item.go Updated imports, field types, and methods in structs.
pubsubjobs/listener.go Adjusted error handling and pipeline restarts, renamed variables for clarity.
tests/configs/.../.rr-init.yaml Updated version string, added dead_letter_topic field, changed consume field.
tests/configs/.../.rr-pq.yaml Updated version string, modified spacing around list elements in consume.
tests/go.mod Updated versions of dependencies.
tests/jobs_test.go Replaced logger.Plugin{} with l in a function, added assertions for log messages using oLogger.
tests/php_test_....../jobs_err.php Updated task handling logic and error management in job consumer loop.
tests/php_test_....../jobs_ok.php Changed method calls within while loop for task acknowledgment and error handling.
tests/php_test_....../jobs_ok_pq.php Modified method call within a while loop to update task handling logic.

Sequence Diagram(s)

(The changes are too varied or simple to warrant sequence diagrams.)

Poem

In the warren of our code, we prance,
With updated tools, we now advance.
Tasks will flow and errors will flee,
In perfect harmony, just wait and see.
🍃⏩✨


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: 1

Outside diff range and nitpick comments (11)
pubsubjobs/listener.go (5)

5-5: Import Error Handling Package

The errors package is imported but not used. Consider removing it if not needed.


9-9: Import Events Package

The events package is imported but not used. Consider removing it if not needed.


15-17: Define Constants Clearly

The restartStr constant is defined but not used within the provided code. Ensure it is necessary or remove it.


33-34: Initialize Headers Properly

Consider initializing item.headers only if it is nil to avoid unnecessary allocations.

if item.headers == nil {
  item.headers = make(map[string][]string, 2)
}

Line range hint 51-59: Reduce Listeners Correctly

Ensure that the listener count is reduced correctly using atomic operations.

if st != nil && st.Message() == "grpc: the client connection is closing" {
  if atomic.LoadUint32(&d.listeners) > 0 {
    atomic.AddUint32(&d.listeners, ^uint32(0))
  }
  d.log.Debug("listener was stopped")
  return
}
tests/jobs_test.go (5)

Line range hint 3-3: Update Imports

Ensure that all imports are necessary and correctly used in the tests.


Line range hint 3-3: Update Imports

Ensure that all imports are necessary and correctly used in the tests.


Line range hint 3-3: Update Imports

Ensure that all imports are necessary and correctly used in the tests.


Line range hint 3-3: Update Imports

Ensure that all imports are necessary and correctly used in the tests.


Line range hint 3-3: Update Imports

Ensure that all imports are necessary and correctly used in the tests.

pubsubjobs/driver.go (1)

279-280: State Method Not Implemented

The State method is not implemented. Ensure that users are aware of this limitation.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 147c929 and fdbb9d0.

Files ignored due to path filters (4)
  • go.sum is excluded by !**/*.sum
  • go.work is excluded by !**/*.work
  • go.work.sum is excluded by !**/*.sum
  • tests/go.sum is excluded by !**/*.sum
Files selected for processing (16)
  • .github/workflows/linters.yml (1 hunks)
  • .gitignore (1 hunks)
  • .golangci.yml (1 hunks)
  • go.mod (2 hunks)
  • plugin.go (2 hunks)
  • pubsubjobs/config.go (3 hunks)
  • pubsubjobs/driver.go (13 hunks)
  • pubsubjobs/item.go (10 hunks)
  • pubsubjobs/listener.go (3 hunks)
  • tests/configs/.rr-init.yaml (3 hunks)
  • tests/configs/.rr-pq.yaml (2 hunks)
  • tests/go.mod (4 hunks)
  • tests/jobs_test.go (2 hunks)
  • tests/php_test_files/jobs/jobs_err.php (1 hunks)
  • tests/php_test_files/jobs/jobs_ok.php (1 hunks)
  • tests/php_test_files/jobs/jobs_ok_pq.php (1 hunks)
Files skipped from review due to trivial changes (6)
  • .github/workflows/linters.yml
  • .gitignore
  • .golangci.yml
  • go.mod
  • tests/configs/.rr-init.yaml
  • tests/configs/.rr-pq.yaml
Additional comments not posted (40)
tests/php_test_files/jobs/jobs_ok.php (2)

15-15: Ensure proper error handling for task acknowledgment.

The ack() method can throw exceptions. Ensure that any potential side effects or necessary cleanups are handled within the catch block.


17-17: Verify the existence and initialization of $rr.

Ensure that the $rr object is properly initialized before being used to log errors. If not, this will cause a runtime error.

tests/php_test_files/jobs/jobs_ok_pq.php (2)

16-16: Ensure proper error handling for task acknowledgment.

The ack() method can throw exceptions. Ensure that any potential side effects or necessary cleanups are handled within the catch block.


18-18: Verify the existence and initialization of $rr.

Ensure that the $rr object is properly initialized before being used to log errors. If not, this will cause a runtime error.

tests/php_test_files/jobs/jobs_err.php (6)

16-16: Ensure the header line "attempts" is present.

Before calling getHeaderLine("attempts"), verify that this header line exists to avoid potential issues.


19-19: Ensure proper error handling for task acknowledgment.

The ack() method can throw exceptions. Ensure that any potential side effects or necessary cleanups are handled within the catch block.


21-21: Verify the usage of withHeader.

Ensure that the withHeader method properly updates the task headers and that it is used correctly in this context.


22-22: Verify the usage of withDelay.

Ensure that the withDelay method properly sets the delay for the task and that it is used correctly in this context.


23-23: Verify the usage of requeue.

Ensure that the requeue method properly requeues the task and that it is used correctly in this context.


27-27: Verify the existence and initialization of $rr.

Ensure that the $rr object is properly initialized before being used to log errors. If not, this will cause a runtime error.

pubsubjobs/config.go (3)

9-14: New constants added for configuration keys.

The new constants skipTopicKey, projectIDKey, deadLetterTopic, topicKey, maxDeliveryAttempts, and priorityKey are added. Ensure these keys are used consistently throughout the codebase.


26-29: New fields added to the config struct.

The new fields DeadLetterTopic, MaxDeliveryAttempts, and Priority are added to the config struct. Ensure these fields are correctly populated and used in the codebase.


49-52: Default values for new configuration fields.

The InitDefaults function now sets default values for MaxDeliveryAttempts if DeadLetterTopic is specified. Ensure these defaults are appropriate and documented.

plugin.go (2)

61-61: DriverFromConfig method updated.

The DriverFromConfig method now uses the pubsubjobs.FromConfig function. Ensure that the FromConfig function handles all necessary configurations and dependencies.


65-65: DriverFromPipeline method updated.

The DriverFromPipeline method now uses the pubsubjobs.FromPipeline function. Ensure that the FromPipeline function handles all necessary configurations and dependencies.

pubsubjobs/listener.go (6)

27-27: Context Propagation

Ensure that ctxspan is properly closed in all error paths to avoid potential memory leaks.


45-47: Handle Context Canceled Error

The context canceled error is being handled correctly by setting d.listeners to 0.


66-69: Restart Pipeline on Failure

The logic to restart the pipeline on failure is correctly implemented.


73-125: Dead-Letter Handling

Ensure the dead-letter handling logic is thoroughly tested. This is a critical section that handles failed messages.


128-128: LGTM!

The atomicCtx function correctly initializes the context and cancel function.


Line range hint 130-130: LGTM!

The checkCtxAndCancel function correctly handles context cancellation based on listener count.

tests/go.mod (4)

3-3: Update Go Version

The Go version is updated from 1.22.4 to 1.22.5. Ensure compatibility with all dependencies.


5-5: Replace Module Path

The module path for google-pub-sub is replaced with a local path. Ensure this is intentional for local development.


8-24: Update Dependencies

The dependencies are updated to their latest versions. Ensure compatibility and test thoroughly.


Line range hint 29-97: Indirect Dependencies

Multiple indirect dependencies are updated. Ensure these updates do not introduce any breaking changes.

pubsubjobs/item.go (8)

95-95: Handle JSON Marshal Error

Ensure that the error handling for JSON marshaling is thorough.


112-112: Auto-Ack Handling

Ensure that the auto-ack logic is correctly implemented to avoid message loss.


136-171: Nack Handling

Ensure that the negative acknowledgment logic is correctly implemented to handle message requeueing and error conditions.


173-208: Requeue Handling

Ensure that the requeue logic is correctly implemented to handle message requeueing and error conditions.


276-288: Unpack Message

Ensure that the message unpacking logic is correctly implemented to handle all attributes and potential errors.


309-325: Handle Acknowledgment Result

Ensure that the acknowledgment result handling logic is correctly implemented to manage all possible statuses.


Line range hint 218-226: Convert Job to Item

Ensure that the conversion logic from jobs.Message to Item is correctly implemented to handle all fields.


Line range hint 296-306: Boolean Conversion Functions

Ensure that the boolean conversion functions are correctly implemented and used where appropriate.

tests/jobs_test.go (2)

211-211: Use Mock Logger

The mock logger is used correctly for testing purposes.


283-290: Log Assertions

Ensure that the log assertions are correctly verifying the expected log messages.

pubsubjobs/driver.go (5)

127-129: Initialize Event Bus

Ensure that the event bus is correctly initialized and used.


207-209: Initialize Event Bus

Ensure that the event bus is correctly initialized and used.


249-249: Job Push Handling

Ensure that the job push logic is correctly implemented to handle all possible errors and conditions.


249-249: Pipeline Run Handling

Ensure that the pipeline run logic is correctly implemented to handle all possible errors and conditions.


249-249: Pipeline Pause Handling

Ensure that the pipeline pause logic is correctly implemented to handle all possible errors and conditions.

require dirname(__DIR__) . "/vendor/autoload.php";

$consumer = new Spiral\RoadRunner\Jobs\Consumer();

while ($task = $consumer->waitTask()) {
try {
sleep(15);
$task->complete();
sleep(15);
Copy link

Choose a reason for hiding this comment

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

Consider reducing the sleep duration.

The sleep(15) call might introduce unnecessary delays. Evaluate if a shorter duration would suffice or if there are more efficient ways to handle the delay.

@rustatian rustatian marked this pull request as ready for review July 3, 2024 22:08
@rustatian rustatian merged commit d8ec2d7 into master Jul 3, 2024
5 of 6 checks passed
@rustatian rustatian deleted the feature/jobs-api-update branch July 3, 2024 22:08
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.

1 participant