Skip to content

pass dispatchAfterCommit into custom worker constructor wihtout breaking changes #521

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

Conversation

oprudkyi
Copy link
Contributor

  • align constructors for custom workers and RabbitMQQueue
  • add extra option 'custom_worker_type' => 'with_dispatch_after_commit', to allow change type of constructor (not required, default - old behavior)

this is version of #513 without breaking changes (things handled via extra option)

@khepin please check

- align constructors for custom workers and RabbitMQQueue
- add extra option
  'custom_worker_type' =>  'with_dispatch_after_commit',
  to allow change type of constructor
@oprudkyi oprudkyi changed the title pass dispatchAfterCommit into custom worker pass dispatchAfterCommit into custom worker constructor wihtout breaking changes Feb 17, 2023
@@ -95,6 +96,7 @@ protected function createConnection(array $config): AbstractConnection
*/
protected function createQueue(
string $worker,
string $customWorkerType,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's your reasoning behind making this the 2nd arg? Doing this may break if others rely upon extending this function so we would have to do a major change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @M-Porter
I some kind of confused

Copy link
Collaborator

Choose a reason for hiding this comment

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

To be clear: v13.1.0 was a breaking minor version by the laravel library itself. We had to no choice but to follow suite as doing composer update for a patch version would have broken so to mitigate the problem created by laravel that was the only solution.

Yes, it's protected, but nothing keeps you from writing your own connector which others do and this would break parent::createQueue() calls.

Comment on lines +111 to +116
switch ($customWorkerType) {
case 'with_dispatch_after_commit':
return new $worker($connection, $queue, $dispatchAfterCommit, $options);
default:
return new $worker($connection, $queue, $options);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this feels like a hack rather than a solution to the problem.

would like to see a move towards using factory make functions that return a class so we don't have to rely on params being perfectly matched up as long as they all share an underlying contract. this is something @khepin and I have discussed but are yet to really dig into a good solution yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, the library right now have a major bug which blocks real use of it (because call incompatible with Laravel )
I would prefer it fixed in some compatible way (right now we rely on custom fork)

Copy link
Collaborator

Choose a reason for hiding this comment

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

nope, nope, nope

This does not only feels like a hack... it is a hack.

Copy link
Collaborator

Choose a reason for hiding this comment

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

the library right now have a major bug which blocks real use of it

Nothing is preventing you from creating you own $worker class compatible with the underlying Queue contracts and in the constructor doing what you need to. You do not have to extend VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue to use this library.

I agree its not great that the constructors are no aligned but the fix is not a hack to make it work how you want it to but update to use factories to work with everyones code.

@@ -42,6 +42,7 @@ public function connect(array $config): Queue

$queue = $this->createQueue(
Arr::get($config, 'worker', 'default'),
Arr::get($config, 'custom_worker_type', 'default'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This config item does not follow other connection properties available to all drivers.
Rather put this in the options property [ options => [ 'custom_option' => 'value' ]]

Copy link
Collaborator

@adm-bome adm-bome left a comment

Choose a reason for hiding this comment

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

Won't approve such changes.

This can be solved/addressed, without aletering the library's code.
As I already wrote above. See also my comments in PR #513

@adm-bome adm-bome closed this Feb 28, 2023
@M-Porter
Copy link
Collaborator

M-Porter commented Mar 1, 2023

Agreed with adm-bome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants