This commit is contained in:
2023-11-30 11:40:04 +08:00
parent 8781b4dc45
commit 04b1aab406
+63 -63
View File
@@ -17,16 +17,16 @@ use Swoole\Coroutine;
abstract class BaseProcess implements OnProcessInterface abstract class BaseProcess implements OnProcessInterface
{ {
protected bool $isStop = false; private bool $stop = false;
protected bool $redirect_stdin_and_stdout = FALSE; protected bool $redirect_stdin_and_stdout = FALSE;
protected int $pipe_type = SOCK_DGRAM; protected int $pipe_type = SOCK_DGRAM;
protected bool $enable_coroutine = false; protected bool $enable_coroutine = false;
/** /**
@@ -43,82 +43,82 @@ abstract class BaseProcess implements OnProcessInterface
public \Kiri\Di\Container $container; public \Kiri\Di\Container $container;
public string $name = ''; public string $name = '';
/** /**
* @return string * @return string
*/ */
public function getName(): string public function getName(): string
{ {
if (empty($this->name)) { if (empty($this->name)) {
$this->name = uniqid('p.'); $this->name = uniqid('p.');
} }
return $this->name; return $this->name;
} }
/** /**
* @return bool * @return bool
*/ */
public function isStop(): bool public function isStop(): bool
{ {
return $this->isStop; return $this->stop;
} }
/** /**
* @return bool * @return bool
*/ */
public function getRedirectStdinAndStdout(): bool public function getRedirectStdinAndStdout(): bool
{ {
return $this->redirect_stdin_and_stdout; return $this->redirect_stdin_and_stdout;
} }
/** /**
* @return int * @return int
*/ */
public function getPipeType(): int public function getPipeType(): int
{ {
return $this->pipe_type; return $this->pipe_type;
} }
/** /**
* @return bool * @return bool
*/ */
public function isEnableCoroutine(): bool public function isEnableCoroutine(): bool
{ {
return $this->enable_coroutine; return $this->enable_coroutine;
} }
/** /**
* *
*/ */
public function onProcessStop(): void public function stop(): void
{ {
$this->isStop = true; $this->stop = true;
} }
/** /**
* @return $this * @return $this
*/ */
abstract public function onSigterm(): static; abstract public function onSigterm(): static;
/** /**
* @param $data * @param $data
* @return void * @return void
*/ */
protected function onShutdown($data): void protected function onShutdown($data): void
{ {
$this->isStop = true; $this->stop = true;
$value = Context::get('waite:process:message'); $value = Context::get('waite:process:message');
$this->logger->alert('Process ' . $this->getName() . ' stop'); $this->logger->alert('Process ' . $this->getName() . ' stop');
if (!is_null($value) && Coroutine::exists((int)$value)) { if (!is_null($value) && Coroutine::exists((int)$value)) {
Coroutine::cancel((int)$value); Coroutine::cancel((int)$value);
} }
} }
} }