Compare commits

...

11 Commits

Author SHA1 Message Date
as2252258 5defd5fb30 eee 2024-12-27 21:53:16 +08:00
as2252258 95f52b58fd eee 2024-12-27 18:32:55 +08:00
as2252258 0a97c9b29a eee 2024-12-27 18:30:35 +08:00
as2252258 3336573b4d eee 2024-12-27 18:29:06 +08:00
as2252258 44187c2354 eee 2024-12-27 18:26:49 +08:00
as2252258 a058f3ed99 eee 2024-12-27 18:21:30 +08:00
as2252258 faff485006 eee 2024-12-27 17:59:52 +08:00
as2252258 e2b012126a eee 2024-12-27 17:58:52 +08:00
as2252258 b36e21d8ee eee 2024-11-19 09:12:45 +08:00
as2252258 d191296ecc eee 2024-11-19 09:12:29 +08:00
as2252258 03825dcb09 eee 2024-11-19 09:10:12 +08:00
4 changed files with 32 additions and 22 deletions
+1 -3
View File
@@ -149,9 +149,7 @@ class HotReload extends AbstractProcess
public function readFile(string $directory): void public function readFile(string $directory): void
{ {
if (str_ends_with($directory, '.php') === true) { if (str_ends_with($directory, '.php') === true) {
$wd = inotify_add_watch($this->pipe, $directory, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE); inotify_add_watch($this->pipe, $directory, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE);
$this->watches[] = $wd;
} }
} }
+11 -6
View File
@@ -2,6 +2,7 @@
namespace Kiri\Server\Handler; namespace Kiri\Server\Handler;
use Kiri;
use Kiri\Server\Abstracts\Server; use Kiri\Server\Abstracts\Server;
use Kiri\Server\Contract\OnPipeMessageInterface; use Kiri\Server\Contract\OnPipeMessageInterface;
@@ -20,13 +21,17 @@ class OnPipeMessage extends Server
*/ */
public function onPipeMessage(\Swoole\Server $server, int $src_worker_id, mixed $message): void public function onPipeMessage(\Swoole\Server $server, int $src_worker_id, mixed $message): void
{ {
if (is_string($message)) { try {
$message = unserialize($message); if (is_string($message)) {
$message = unserialize($message);
}
if (!is_object($message) || !($message instanceof OnPipeMessageInterface)) {
return;
}
call_user_func([$message, 'process'], $server, $src_worker_id);
} catch (\Throwable $throwable) {
Kiri::getLogger()->error(throwable($throwable));
} }
if (!is_object($message) || !($message instanceof OnPipeMessageInterface)) {
return;
}
call_user_func([$message, 'process'], $server, $src_worker_id);
} }
+16 -11
View File
@@ -5,6 +5,8 @@ namespace Kiri\Server\Processes;
use Swoole\Coroutine; use Swoole\Coroutine;
use Swoole\Process; use Swoole\Process;
use const SIGHUP;
use const SIGTERM;
/** /**
* *
@@ -125,26 +127,29 @@ abstract class AbstractProcess implements OnProcessInterface
{ {
$this->process = $process; $this->process = $process;
if ($this->enable_coroutine) { if ($this->enable_coroutine) {
Coroutine::set([ $array['enable_deadlock_check'] = false;
'enable_deadlock_check' => false, $array['deadlock_check_disable_trace'] = false;
'deadlock_check_disable_trace' => false, $array['exit_condition'] = [$this, 'exit_condition'];
'exit_condition' => function () { Coroutine::set($array);
return Coroutine::stats()['coroutine_num'] === 0; Coroutine::create(fn() => $this->coroutineWaitSignal());
}
]);
Coroutine::create(fn () => $this->coroutineWaitSignal());
} else { } else {
pcntl_signal(SIGTERM, [$this, 'pointWaitSignal']); pcntl_signal(SIGTERM | SIGINT | SIGUSR1, [$this, 'pointWaitSignal']);
} }
return $this; return $this;
} }
public function exit_condition(): bool
{
return Coroutine::stats()['coroutine_num'] === 0;
}
/** /**
* @param $data * @param $signal
* @return void * @return void
*/ */
public function pointWaitSignal($data): void public function pointWaitSignal($signal): void
{ {
$this->stop = true; $this->stop = true;
+4 -2
View File
@@ -77,8 +77,10 @@ class Task
if (is_null($data)) { if (is_null($data)) {
return null; return null;
} }
$data[0] = Kiri::getDi()->get($data[0]); [$handler, $params] = [$data[0], $data[1]];
return call_user_func($data, $task_id, $src_worker_id);
$handler[0] = Kiri::getDi()->get($handler[0]);
return call_user_func($handler, $task_id, $src_worker_id, $params);
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
return $this->exception->emit($throwable, response()); return $this->exception->emit($throwable, response());
} }