-
-
Notifications
You must be signed in to change notification settings - Fork 296
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
Comments
Now we can do smth like /** @var StorageService $storage */
$storage = Yii::createObject(StorageService::class); inside the @samdark @SilverFire @airani @luke- go to discussion |
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. |
@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. |
I dont see any problems. 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. |
@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?The text was updated successfully, but these errors were encountered: