eee
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
namespace Kiri\Server\Processes;
|
||||
|
||||
|
||||
use Kiri\Di\Context;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Process;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -15,6 +15,9 @@ abstract class AbstractProcess implements OnProcessInterface
|
||||
private bool $stop = false;
|
||||
|
||||
|
||||
public Process $process;
|
||||
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
@@ -109,24 +112,46 @@ abstract class AbstractProcess implements OnProcessInterface
|
||||
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @return void
|
||||
*/
|
||||
abstract public function onSigterm(): static;
|
||||
abstract public function onSigterm(): void;
|
||||
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
* @return AbstractProcess
|
||||
*/
|
||||
public function onShutdown(Process $process): static
|
||||
{
|
||||
$this->process = $process;
|
||||
if ($this->enable_coroutine) {
|
||||
Coroutine::create(fn () => $this->coroutineWaitSignal());
|
||||
} else {
|
||||
pcntl_signal(SIGTERM, [$this, 'pointWaitSignal']);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return void
|
||||
*/
|
||||
protected function onShutdown($data): void
|
||||
private function pointWaitSignal($data): void
|
||||
{
|
||||
$this->stop = true;
|
||||
$value = Context::get('waite:process:message');
|
||||
\Kiri::getLogger()->alert('AbstractProcess ' . $this->getName() . ' stop');
|
||||
if (!is_null($value) && Coroutine::exists((int)$value)) {
|
||||
Coroutine::cancel((int)$value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function coroutineWaitSignal(): void
|
||||
{
|
||||
$value = Coroutine::waitSignal(SIGTERM);
|
||||
if ($value) {
|
||||
$this->stop = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user