modify plugin name

This commit is contained in:
2022-06-22 18:43:36 +08:00
parent f83afa3e71
commit 16ea9f3848
2 changed files with 9 additions and 19 deletions
+2 -2
View File
@@ -90,10 +90,10 @@ abstract class BaseProcess implements OnProcessInterface
public function onSigterm(): static public function onSigterm(): static
{ {
if (!Context::inCoroutine()) { if (!Context::inCoroutine()) {
Process::signal(SIGTERM | SIGINT, fn($data) => $this->onShutdown($data)); Process::signal(SIGTERM, fn($data) => $this->onShutdown($data));
} else { } else {
$listen = function () { $listen = function () {
$data = Coroutine::waitSignal(SIGTERM | SIGINT, -1); $data = Coroutine::waitSignal(SIGTERM, -1);
if ($data) { if ($data) {
$this->onShutdown($data); $this->onShutdown($data);
} }
+7 -17
View File
@@ -36,7 +36,6 @@ class ProcessManager
/** /**
* @param string|OnProcessInterface|BaseProcess $customProcess * @param string|OnProcessInterface|BaseProcess $customProcess
* @return array * @return array
* @throws ConfigException
*/ */
public function add(string|OnProcessInterface|BaseProcess $customProcess): array public function add(string|OnProcessInterface|BaseProcess $customProcess): array
{ {
@@ -44,14 +43,11 @@ class ProcessManager
$customProcess = Kiri::getDi()->get($customProcess); $customProcess = Kiri::getDi()->get($customProcess);
} }
$system = sprintf('[%s].Custom Process', Config::get('id', 'system-service'));
$this->logger->alert($system . ' ' . $customProcess->getName() . ' start.');
if (Context::inCoroutine()) { if (Context::inCoroutine()) {
return [$customProcess, $this->resolve($customProcess, $system)]; return [$customProcess, $this->resolve($customProcess)];
} }
$process = new Process($this->resolve($customProcess, $system), $process = new Process($this->resolve($customProcess),
$customProcess->getRedirectStdinAndStdout(), $customProcess->getRedirectStdinAndStdout(),
$customProcess->getPipeType(), $customProcess->getPipeType(),
$customProcess->isEnableCoroutine() $customProcess->isEnableCoroutine()
@@ -73,25 +69,19 @@ class ProcessManager
/** /**
* @param $customProcess * @param BaseProcess $customProcess
* @param $system
* @return Closure * @return Closure
*/ */
public function resolve($customProcess, $system): Closure public function resolve(BaseProcess $customProcess): Closure
{ {
return static function () use ($customProcess, $system) { return static function (Process $process) use ($customProcess) {
$process = func_get_arg(0);
if ($process instanceof Process\Pool) {
$process = $process->getProcess(func_get_arg(1));
}
set_env('environmental', Kiri::PROCESS); set_env('environmental', Kiri::PROCESS);
$system = sprintf('[%s].Custom Process', Config::get('id', 'system-service'));
Kiri::getLogger()->alert($system . ' ' . $customProcess->getName() . ' start.');
if (Kiri::getPlatform()->isLinux()) { if (Kiri::getPlatform()->isLinux()) {
$process->name($system . '(' . $customProcess->getName() . ')'); $process->name($system . '(' . $customProcess->getName() . ')');
} }
$dispatcher = Kiri::getDi()->get(EventDispatch::class);
$dispatcher->dispatch(new OnProcessStart());
$customProcess->onSigterm()->process($process); $customProcess->onSigterm()->process($process);
$dispatcher->dispatch(new OnProcessStop($process));
}; };
} }