Skip to content

pass dispatchAfterCommit into custom worker constructor #513

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

Closed
wants to merge 1 commit into from

Conversation

oprudkyi
Copy link
Contributor

align constructors for custom workers and RabbitMQQueue

so there no need to map somehow constructor in case of custom worker

'worker' => env('RABBITMQ_WORKER', App\Services\CustomRabbitMQQueue::class),

...

use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;

class CustomRabbitMQQueue extends RabbitMQQueue
{

align constructors for custom workers and RabbitMQQueue
@M-Porter
Copy link
Collaborator

I believe the intention for this was for custom workers to extend Queue and implement QueueContract.

That being said, it is a good idea to make those calls consistent.

@oprudkyi
Copy link
Contributor Author

Hi @M-Porter
yes,

we added some tracing into RabbitMQQueue by inheriting it and incompatible constructor make things clumsy

@khepin
Copy link
Collaborator

khepin commented Jan 27, 2023

In its current form, this would be a breaking change and will therefore have to wait on a major version release.
If we wanted to allow a similar behavior prior to that, we'd need to offer a different way of achieving the same result.

@oprudkyi
Copy link
Contributor Author

@khepin well, 13.0.2 also introduces incompatibility with some versions of laravel 9
and as for me it's fix for broken compatibility in v13 , basically the same what 13.0.1 did for 13.0.0 https://github.com/vyuldashev/laravel-queue-rabbitmq/blob/master/CHANGELOG-13x.md

@oprudkyi
Copy link
Contributor Author

oprudkyi commented Jan 27, 2023

@khepin what if there will be some new option

'worker' => env('RABBITMQ_WORKER', App\Services\CustomRabbitMQQueue::class),
'custom_worker_type' =>  'with_dispatch_after_commit',

this will allow to have fix without introduction of breaking changes

jeromegamez added a commit to jeromegamez/vyuldashev-laravel-queue-rabbitmq that referenced this pull request Feb 6, 2023
jeromegamez added a commit to jeromegamez/vyuldashev-laravel-queue-rabbitmq that referenced this pull request Feb 6, 2023
@adm-bome
Copy link
Collaborator

adm-bome commented Feb 28, 2023

Does this work ????

  • No library code adjustments, only adjustments in your own Class and config.
<?php

namespace App\Queue;

use Illuminate\Support\Arr;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;

class CustomRabbitMQQueue extends RabbitMQQueue
{

    public function __construct(
        AbstractConnection $connection,
        string $default,
        array $options = []
    ) {
        $dispatchAfterCommit = Arr::pull($options, 'after_commit', false);
        parent::__construct($connection, $default, $dispatchAfterCommit, $options);
    }

and in the connection config ( move the after_commit option to the queue options)

#/config/queue.php
'connections' => [
    // ...

    'rabbitmq' => [
        // ...
        
        // 'after_commit' => true
        'options' => [

            'queue' => [
                // ...
                'after_commit' => true
                'job' => \App\Queue\Jobs\RabbitMQJob::class,
            ],
        ],
    ],

    // ... 

@adm-bome
Copy link
Collaborator

@khepin
And I agree to align the constructor calls.

When dispatchAfterCommit was introduced into Laravel and eventually was implemented into this library... the contructor calls had to be already aligned. This library checks if the Worker class (Queue) is an instance of RabibitMQQueue:class, so the call is wrong because the constructor of the RabibitMQQueue:class is already different.

If people are depending on the constructor of the RabibitMQQueue:class, people had already noticed issues and had to correct this with a sort of sollution I presented above.

@oprudkyi
Copy link
Contributor Author

Hi @adm-bome
everything works (currently we're using fork, I think using own RabbitMQConnector is even more simpler option ) , but this PR will allow to avoid introducing yet another dependency in our code

@adm-bome
Copy link
Collaborator

I think using own RabbitMQConnector is even more simpler option

Not really, if you want to replace all classes then use a fork or write your own implementation of a driver 😄

The contructors calls must align with the default constructor of RabibitMQQueue:class.

As i mentioned above _the contructor calls had to be already aligned_ and your problem should have never emerge.
When this was noticed in the beginning, when review-ing the initial merge of the feature dispatchAfterCommit, all was good for now.

jeromegamez added a commit to jeromegamez/vyuldashev-laravel-queue-rabbitmq that referenced this pull request Mar 6, 2023
jeromegamez added a commit to jeromegamez/vyuldashev-laravel-queue-rabbitmq that referenced this pull request Mar 17, 2023
@adm-bome
Copy link
Collaborator

Closing this, because the connector was refactored and the Factory uses a different approach for the constructor (one single config object)

@adm-bome adm-bome closed this Apr 11, 2023
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.

4 participants