eee
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Kiri\Server\Processes;
|
|||||||
|
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Swoole\Process;
|
use Swoole\Process;
|
||||||
|
use const SIGHUP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -125,30 +126,49 @@ 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, [$this, 'pointWaitSignal']);
|
||||||
|
pcntl_signal(\SIGINT, [$this, 'pointWaitSignal']);
|
||||||
|
pcntl_signal(\SIGUSR1, [$this, 'pointWaitSignal']);
|
||||||
|
pcntl_signal(SIGHUP, [$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;
|
||||||
|
|
||||||
$this->onSigterm();
|
$this->onSigterm();
|
||||||
|
switch ($signal) {
|
||||||
|
case \SIGTERM:
|
||||||
|
case \SIGUSR1:
|
||||||
|
case \SIGINT:
|
||||||
|
// some stuff before stop consumer e.g. delete lock etc
|
||||||
|
pcntl_signal($signal, SIG_DFL); // restore handler
|
||||||
|
posix_kill(posix_getpid(), $signal);
|
||||||
|
break; // kill self with signal, see https://www.cons.org/cracauer/sigint.html
|
||||||
|
case SIGHUP:
|
||||||
|
// some stuff to restart consumer
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user