Compare commits

...

2 Commits

Author SHA1 Message Date
as2252258 858b9bc9f9 eee 2024-04-24 14:31:06 +08:00
as2252258 4cbd1fb500 eee 2024-04-24 14:17:09 +08:00
4 changed files with 38 additions and 8 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ trait TraitServer
*/ */
private function onPcntlSignal($signal, $callback): void private function onPcntlSignal($signal, $callback): void
{ {
pcntl_signal($signal, $callback); \pcntl_signal($signal, $callback);
} }
+1 -1
View File
@@ -67,7 +67,7 @@ class OnRequest implements OnRequestInterface
public DataGrip $dataGrip) public DataGrip $dataGrip)
{ {
$this->responseEmitter = $this->response->emmit; $this->responseEmitter = $this->response->emmit;
$exception = \config('request.exception'); $exception = \config('exception.http');
if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) { if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) {
$exception = ExceptionHandlerDispatcher::class; $exception = ExceptionHandlerDispatcher::class;
} }
+1 -1
View File
@@ -63,7 +63,7 @@ class HotReload extends BaseProcess
if (Context::inCoroutine()) { if (Context::inCoroutine()) {
Coroutine::create(fn() => $this->onShutdown(Coroutine::waitSignal(SIGTERM | SIGINT))); Coroutine::create(fn() => $this->onShutdown(Coroutine::waitSignal(SIGTERM | SIGINT)));
} else { } else {
pcntl_signal(SIGTERM, [$this, 'onStop']); \pcntl_signal(SIGTERM, [$this, 'onStop']);
} }
return $this; return $this;
} }
+35 -5
View File
@@ -4,7 +4,14 @@ namespace Kiri\Server\Task;
use Kiri; use Kiri;
use Kiri\Router\Base\ExceptionHandlerDispatcher;
use Kiri\Router\DataGrip;
use Kiri\Router\Interface\ExceptionHandlerInterface;
use Kiri\Server\Constant; use Kiri\Server\Constant;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Swoole\Server; use Swoole\Server;
/** /**
@@ -13,6 +20,25 @@ use Swoole\Server;
class Task class Task
{ {
public ExceptionHandlerInterface $exception;
/**
* @param ContainerInterface $container
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __construct(public ContainerInterface $container)
{
$exception = \config('exception.task');
if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) {
$exception = ExceptionHandlerDispatcher::class;
}
$this->exception = $this->container->get($exception);
}
/** /**
* @param Server $server * @param Server $server
* @return void * @return void
@@ -53,12 +79,16 @@ class Task
*/ */
public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): mixed public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): mixed
{ {
$data = json_decode($data, true); try {
if (is_null($data)) { $data = json_decode($data, true);
return null; if (is_null($data)) {
return null;
}
$data[0] = Kiri::getDi()->get($data[0]);
return call_user_func($data, $task_id, $src_worker_id);
} catch (\Throwable $throwable) {
return $this->exception->emit($throwable, response());
} }
$data[0] = Kiri::getDi()->get($data[0]);
return call_user_func($data, $task_id, $src_worker_id);
} }