8000 [Messenger] Use newer version of Beanstalkd bridge library by HypeMC · Pull Request #60040 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Use newer version of Beanstalkd bridge library #60040

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

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

HypeMC
Copy link
Contributor
@HypeMC HypeMC commented Mar 25, 2025
Q A
Branch? 7.3
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

Currently, the Beanstalkd bridge supports version 4 of pda/pheanstalk, which is no longer maintained. The latest version is v7, and the actively maintained versions appear to be v5 and v7. Version 7 was released just a week after v6, and from what I can tell, v6 is not supported as no patch versions have ever been released for it.

This PR bumps support to the maintained versions. I've split it into two commits to make reviewing easier:

  1. The first commit upgrades the library version and updates the code for compatibility.
  2. The second commit adds a reconnect mechanism. Version 4 had a built-in one, which was removed in v5+. This commit reimplements that logic in the Connection class.

I'm not sure which version of Symfony this should target. It's not exactly a new feature, but the changes are significant.

10000
"pda/pheanstalk": "^4.0",
"pda/pheanstalk": "^5.1|^7.0",
Copy link
Contributor Author
@HypeMC HypeMC Mar 25, 2025

Choose a reason for hiding this comment

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

These are the versions that have the disconnect() method, which is needed for the reconnect mechanism. Also, v7 supports only PHP 8.3+, while v5 supports PHP 8.1+.

Comment on lines 172 to 186
return $this->client->watchOnly($this->tube)->reserveWithTimeout($this->timeout);
if ($this->client->watch($this->tube) > 1) {
foreach ($this->client->listTubesWatched() as $tube) {
if ((string) $tube !== (string) $this->tube) {
$this->client->ignore($tube);
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The watchOnly method was removed, this implements similar behavior.

Comment on lines 137 to 142
$job = $this->client->useTube($this->tube)->put(
$this->client->useTube($this->tube);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some methods like useTube are no longer chainable.

@@ -503,3 +517,7 @@ public function testSendWithRoundedDelay()
$connection->send($body, $headers, $delay);
}
}

interface PheanstalkInterface extends PheanstalkPublisherInterface, PheanstalkSubscriberInterface, PheanstalkManagerInterface
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The PheanstalkInterface was split into multiple interfaces. Since the client implements all of them, it's hard to mock. This is a helper interface to make mocking easier.

try {
return $command();
} catch (ConnectionException) {
$this->client->disconnect();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what to do about the Psalm errors. Even though the disconnect() method wasn't added to the interfaces in v5 (to avoid BC breaks), it was added to the Pheanstalk class itself, which is what's used here, so the method always exists. I could use method_exists(), but that feels redundant. The method was added to the interfaces in v7, but that version requires PHP 8.3.

@fabpot
Copy link
Member
fabpot commented Mar 26, 2025

Thank you @HypeMC.

@fabpot fabpot merged commit e282c2f into symfony:7.3 Mar 26, 2025
4 of 11 checks passed
@HypeMC HypeMC deleted the beanstalk-5 branch March 26, 2025 09:46
@fabpot fabpot mentioned this pull request May 2, 2025
fabpot added a commit that referenced this pull request May 8, 2025
…alk (HypeMC)

This PR was merged into the 7.3 branch.

Discussion
----------

[Messenger] Fix integration with newer versions of Pheanstalk

| Q             | A
| ------------- | ---
| Branch?       | 7.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Follow-up to #60040.

When I updated the Pheanstalk library, I missed the fact that version 4 internally tracked the [used](https://github.com/pheanstalk/pheanstalk/blob/1459f2f62dddfe28902e0584708417dddd79bd70/src/Pheanstalk.php#L316-L324)/[watched](https://github.com/pheanstalk/pheanstalk/blob/1459f2f62dddfe28902e0584708417dddd79bd70/src/Pheanstalk.php#L329-L337) tube. This was removed in newer versions, so now every call to `useTube()` or `watch()` sends a command to Beanstalkd, leading to unnecessary bandwidth consumption.

This PR adds simple tracking logic to avoid redundant calls to those functions.

Commits
-------

b766607 [Messenger] Fix integration with newer version of Pheanstalk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0