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

Allow the QueuedJobService implementation to be configured on a per-runner basis #206

Open
robbieaverill opened this issue Aug 30, 2018 · 0 comments

Comments

@robbieaverill
Copy link
Contributor

robbieaverill commented Aug 30, 2018

If my project has two separate runners:

  • DoormanRunner for immediate queue processing
  • QueueRunner for multi server processing of a longer running queue

It'd be good to be able to configure the QueuedJobService implementation that is used for each runner. At the moment they always return QueuedJobService::singleton() via BaseRunner::getService().

We could change this to use something configuration based, for example:

class BaseRunner
{
    protected $serviceClass = QueuedJobService::class; // default implementation
    protected $service;

    public function setService(QueuedJobService $service)
    {
         $this->service = $service;
         return $this;
    }

    public function getService()
    {
        if (!$this->service) {
            $this->service = Injector::inst()->get($this->serviceClass);
        }
        return $this->service;
}
SilverStripe\Core\Injector\Injector:
  MyQueueRunner:
    properties:
      Service: '%$MyCustomQueuedJobService'

There's other places where the service class is loaded too, so we'd also need to consider how to load the right job service in various points of the API - this example would only work when loaded from runners, and we don't want to redefine DI config in multiple places.

It's also worth noting that the way the config works at the moment is that the QueuedJobService class defines the runner as a dependency of it, so really BaseRunner::getService() should be returning the class that it's injected into.

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

No branches or pull requests

2 participants