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

Job execute method #59

Closed
CTOlet opened this issue Jun 2, 2017 · 4 comments
Closed

Job execute method #59

CTOlet opened this issue Jun 2, 2017 · 4 comments

Comments

@CTOlet
Copy link

CTOlet commented Jun 2, 2017

@zhuravljov Why dont you use Yii::$container->invoke([$job, 'execute']); instead of $job->execute($this);here? It will be very useful for resolving dependencies via DI container. Passing the queue object is useless IMO, we can set it to property of the job if needed. Or maybe there is another ways to simply resolve them?

@CTOlet
Copy link
Author

CTOlet commented Jun 2, 2017

Now we can do smth like

/** @var StorageService $storage */
$storage = Yii::createObject(StorageService::class);

inside the execute($queue) method.

@samdark @SilverFire @airani @luke- go to discussion

@zhuravljov
Copy link
Member

That doesn't make sense. If you try to add DI param to execute method, fatal error will be raised, because method defined inside job interface.

@CTOlet
Copy link
Author

CTOlet commented Jun 6, 2017

@zhuravljov Yeap, that is exactly what I mean, the problem is on the Job interface. I have rewritten that interface before opening this issue and DI works perfectly. But currently implementation limits us.

@zhuravljov
Copy link
Member

I dont see any problems.
You can make base class that contains separate method for injections:

abstract class BaseJob extends Object implements Job
{
    public function execute($queue)
    {
        if (method_exists($this, 'executeByDI')) {
            Yii::$container->invoke([$this, 'executeByDI']);
        } else {
            throw new InvalidCallException('Method executeByDI not exists.');
        }
    }
}

Override this method and use DI params.

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

No branches or pull requests

2 participants