This commit is contained in:
2023-04-22 02:16:02 +08:00
parent 61bd740832
commit ace208f467
+2 -3
View File
@@ -68,15 +68,14 @@ class Task implements TaskInterface
* @param array $handler * @param array $handler
* @param int|null $workerId * @param int|null $workerId
* @return void * @return void
* @throws ReflectionException * @throws
*/ */
public function dispatch(array $handler, ?int $workerId = null): void public function dispatch(array $handler, ?int $workerId = null): void
{ {
/** @var Server $server */ /** @var Server $server */
$server = \Kiri::service()->get('server'); $server = \Kiri::service()->get('server');
if (is_null($workerId)) { if (is_null($workerId)) {
$worker = $server->setting[Constant::OPTION_TASK_WORKER_NUM]; $workerId = rand(0, $server->setting[Constant::OPTION_TASK_WORKER_NUM] - 1);
$workerId = rand(0, $worker);
} }
$server->task(json_encode($handler), $workerId); $server->task(json_encode($handler), $workerId);
} }