modify plugin name
This commit is contained in:
@@ -7,6 +7,7 @@ use Kiri;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Server\SwooleServerInterface;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
|
||||
@@ -17,17 +18,15 @@ class AsyncTaskExecute extends Component
|
||||
{
|
||||
|
||||
|
||||
public TaskManager $hashMap;
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @param TaskManager $hashMap
|
||||
* @param ContainerInterface $container
|
||||
* @param array $config
|
||||
* @throws Exception
|
||||
*/
|
||||
public function init()
|
||||
public function __construct(public TaskManager $hashMap, public ContainerInterface $container, array $config = [])
|
||||
{
|
||||
$this->hashMap = $this->getContainer()->get(TaskManager::class);
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,9 +43,8 @@ class AsyncTaskExecute extends Component
|
||||
if (is_string($handler)) {
|
||||
$handler = $this->handle($handler, $params);
|
||||
}
|
||||
$container = $this->getContainer();
|
||||
if ($container->has(SwooleServerInterface::class)) {
|
||||
$server = $container->get(SwooleServerInterface::class);
|
||||
if ($this->container->has(SwooleServerInterface::class)) {
|
||||
$server = $this->container->get(SwooleServerInterface::class);
|
||||
if ($workerId < 0 || $workerId > $server->setting['task_worker_num']) {
|
||||
$workerId = random_int(0, $server->setting['task_worker_num'] - 1);
|
||||
}
|
||||
@@ -69,7 +67,7 @@ class AsyncTaskExecute extends Component
|
||||
if (!class_exists($handler) && $this->hashMap->has($handler)) {
|
||||
$handler = $this->hashMap->get($handler);
|
||||
}
|
||||
$implements = $this->getContainer()->getReflect($handler);
|
||||
$implements = $this->container->getReflect($handler);
|
||||
if (!in_array(OnTaskInterface::class, $implements->getInterfaceNames())) {
|
||||
throw new Exception('Task must instance ' . OnTaskInterface::class);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace Kiri\Task;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Core\HashMap;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Swoole\Server;
|
||||
|
||||
@@ -17,10 +19,13 @@ class TaskManager extends Component
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ContainerInterface $container
|
||||
* @param array $config
|
||||
* @throws Exception
|
||||
*/
|
||||
public function init()
|
||||
public function __construct(public ContainerInterface $container, array $config = [])
|
||||
{
|
||||
parent::__construct($config);
|
||||
$this->hashMap = new HashMap();
|
||||
}
|
||||
|
||||
@@ -38,7 +43,7 @@ class TaskManager extends Component
|
||||
}
|
||||
|
||||
$task_use_object = $swollen->setting['task_object'] ?? $swollen->setting['task_use_object'] ?? false;
|
||||
$reflect = $this->getContainer()->get(OnServerTask::class);
|
||||
$reflect = $this->container->get(OnServerTask::class);
|
||||
|
||||
$swollen->on('finish', [$reflect, 'onFinish']);
|
||||
if ($task_use_object || $swollen->setting['task_enable_coroutine']) {
|
||||
@@ -79,7 +84,7 @@ class TaskManager extends Component
|
||||
{
|
||||
$task = $this->hashMap->get($key);
|
||||
if (is_string($task)) {
|
||||
$task = $this->getContainer()->get($task);
|
||||
$task = $this->container->get($task);
|
||||
if (!empty($task)) {
|
||||
$this->add($key, $task);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user