This commit is contained in:
2021-08-19 16:15:28 +08:00
parent fb453f674d
commit 99b4aee754
5 changed files with 35 additions and 36 deletions
+25 -32
View File
@@ -17,8 +17,25 @@ abstract class CustomProcess implements \Server\SInterface\CustomProcess
protected bool $enableSwooleCoroutine = true;
/** @var Coroutine\Channel */
protected Coroutine\Channel $channel;
protected bool $isStop = false;
/**
*
*/
public function onProcessStop(): void
{
$this->isStop = true;
}
/**
* @return bool
*/
public function checkProcessIsStop(): bool
{
return $this->isStop === true;
}
/**
@@ -26,22 +43,17 @@ abstract class CustomProcess implements \Server\SInterface\CustomProcess
*/
public function signListen(Process $process): void
{
$this->channel = new Coroutine\Channel(1);
$this->channel->push(1);
if (!$this->enableSwooleCoroutine) {
Process::signal(SIGTERM | SIGKILL, function ($signo)
use ($process) {
putenv('processStatus=exit');
$this->onProcessStop();
$this->waiteExit($process);
});
} else {
go(function () use ($process) {
$data = Coroutine::waitSignal(SIGTERM | SIGKILL, -1);
if ($data) {
putenv('processStatus=exit');
$this->onProcessStop();
$this->waiteExit($process);
}
});
@@ -49,40 +61,21 @@ abstract class CustomProcess implements \Server\SInterface\CustomProcess
}
/**
* @return string
*/
#[Pure] protected function getStatus(): string
{
return env('processStatus', 'working');
}
/**
* @return bool
*/
#[Pure] protected function isExit(): bool
{
return $this->getStatus() == 'exit';
}
/**
*
*/
protected function exit()
protected function exit(): void
{
$this->channel->pop();
$this->channel->close();
putenv('process.status=idle');
}
/**
* @return bool
*/
public function isWorking(): bool
#[Pure] public function isWorking(): bool
{
return $this->channel->isEmpty();
return env('process.status', 'working') == 'working';
}