Compare commits

...

1 Commits

Author SHA1 Message Date
as2252258 903ee0d6ce 改名 2021-11-30 16:00:39 +08:00
+6 -3
View File
@@ -2,6 +2,7 @@
namespace Server\Tasker; namespace Server\Tasker;
use Kiri\Kiri;
use Note\Inject; use Note\Inject;
use Exception; use Exception;
use Kiri\Abstracts\BaseObject; use Kiri\Abstracts\BaseObject;
@@ -21,10 +22,9 @@ class AsyncTaskExecute extends BaseObject
/** /**
* @var SwooleServerInterface * @var SwooleServerInterface|null
*/ */
#[Inject(SwooleServerInterface::class)] public ?SwooleServerInterface $server = null;
public SwooleServerInterface $server;
/** /**
@@ -64,6 +64,9 @@ class AsyncTaskExecute extends BaseObject
*/ */
public function execute(OnTaskInterface|string $handler, array $params = [], int $workerId = null) public function execute(OnTaskInterface|string $handler, array $params = [], int $workerId = null)
{ {
if (!$this->server) {
$this->server = Kiri::getDi()->get(SwooleServerInterface::class);
}
if ($workerId === null || $workerId <= $this->server->setting['worker_num']) { if ($workerId === null || $workerId <= $this->server->setting['worker_num']) {
$workerId = random_int($this->server->setting['worker_num'] + 1, $this->server->setting['task_worker_num']); $workerId = random_int($this->server->setting['worker_num'] + 1, $this->server->setting['task_worker_num']);
} }