Problem/Motivation

In #3397522: Fork Symfony's ContainerAwareTrait and ContainerAwareInterface into core we are trying to reduce the use of ContainerAwareTrait as Symfony has deprecated it.

QueueFactory is container aware because it needs to retrieve queue backend services by name. This could use a service locator instead.

However, there is only one queue backend service in core (queue.database) and there is no base class or interface to identify queue backends.

Steps to reproduce

Proposed resolution

Add an interface to queue backend services.

Add a service locator to QueueFactory.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#19 3416357-nr-bot.txt90 bytesneeds-review-queue-bot

Issue fork drupal-3416357

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

longwave created an issue. See original summary.

arunkumark made their first commit to this issue’s fork.

arunkumark’s picture

Status: Active » Needs review
Spokje’s picture

Status: Needs review » Needs work

Probably wasn't ready for review yet on purpose.

Anyway, to be blatantly obvious: PHPStan baseline needs updating, CR needs to exist and linked.

taraskorpach made their first commit to this issue’s fork.

taraskorpach’s picture

Status: Needs work » Needs review

Based on #5 I've removed PHPStan messages and added the mentions of QueueFactory to the main CR. So, marking it as needs review now.

Spokje’s picture

Status: Needs review » Needs work

Thanks @taraskorpach.

Hate to be that guy, but well, I _am_ that guy: New PHPStan issues showed up in the MR after removing the original one, so back to NW for that.

taraskorpach’s picture

Yes, I've seen it. Issues arose due to the missing ContainerAwareInterface and ContainerAwareTrait, along with the new paths from #3397522: Fork Symfony's ContainerAwareTrait and ContainerAwareInterface into core.

I haven't discovered what @arunkumark has done, but what would be the best solution here? Should we wait until the parent issue is merged, or should we just add the changes from this MR to the parent MR?

longwave’s picture

This should use the service locator pattern, similar to #3414627: Convert StreamWrapperManager to use a service locator, rather than injecting the entire container.

taraskorpach’s picture

I'm not entirely confident in what I'm saying, but how can we use the service locator pattern if we don't know which services to include in the container in the register method of ServiceLocatorTagPass?

In the get method, we use a service name obtained from the Settings. Does this mean we should include the entire container, or am I misunderstanding something? Please clarify this for me. Thank you in advance.

longwave’s picture

However, there is only one queue backend service in core (queue.database) and there is no base class or interface to identify queue backends.

I think we have to:

  • add an interface for queue factory/backend services, similar to CacheFactoryInterface
  • add a tag to services with that interface via autoconfiguration
  • collect all services using that tag in the service locator

This might need to be broken into two issues, to add the interface first, and then deal with the service locator later.

andypost’s picture

It also needs to find contrib usage and file isssues about change

longwave’s picture

@andypost Any ideas how to find affected contrib? There is no interface to search for, which is why we need the other issue. For example I know Redis will be affected by this, but queue_unique is not (because it just extends DatabaseQueueFactory) but I don't know of any other queue backends.

andypost’s picture

longwave’s picture

Status: Needs work » Needs review

Now #3416826: Queue factory services do not conform to an interface has landed we can do this in 11.x, it was simpler than I first thought once I learned about #[AutowireLocator].

We could partially backport this to 10.3.x by injecting the entire container as the second constructor argument, but is it worth the effort?

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Spokje’s picture

There's a (IMHO) valid question from @andypost in the MR and it needs a reroll/rebase after the PHPStan-PHP-Baseline landed, but otherwise this looks fine to me.

longwave’s picture

Status: Needs work » Needs review

Rebased, responded to @andypost's question in the MR.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

I'm still amazed seeing autowire work.

Conversion seems good, the one thread has an answer as mentioned.

  • catch committed f4619055 on 10.3.x
    Issue #3416357 by longwave, arunkumark, taraskorpach, Spokje, andypost:...

  • catch committed dd446b63 on 11.x
    Issue #3416357 by longwave, arunkumark, taraskorpach, Spokje, andypost:...
catch’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

  • catch committed 45ce6061 on 10.3.x
    Revert "Issue #3416357 by longwave, arunkumark, taraskorpach, Spokje,...
catch’s picture

Version: 10.3.x-dev » 11.x-dev

Re-read things here and reverted from 10.3.x, we need to keep that constructor deprecation in and not sure it's worth the juggling to do so per #18.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.