This commit is contained in:
as2252258@163.com
2021-03-01 01:07:29 +08:00
parent be20940927
commit ef02721526
2 changed files with 15 additions and 18 deletions
+14 -16
View File
@@ -23,7 +23,7 @@ class OnWorkerStart extends Callback
{
/** @var int|string 重启信号 */
private int $signal = SIGUSR1 | SIGUSR2;
private int $signal = SIGUSR1 | SIGUSR2 | SIGTERM;
/** @var bool 是否打印 */
@@ -55,7 +55,6 @@ class OnWorkerStart extends Callback
}
/**
* @param Server $server
* @param int $worker_id
@@ -99,21 +98,20 @@ class OnWorkerStart extends Callback
*/
public function onSignal($server, $worker_id)
{
$env = ucfirst(Snowflake::getEnvironmental());
// $env = ucfirst(Snowflake::getEnvironmental());
//
// $receive = Coroutine::waitSignal($this->signal, 30);
// while ($receive === true) {
// if ($this->isPrint === false) {
// $this->warning(sprintf('Receive %s#%d stop event.', $env, $worker_id));
// $this->isPrint = true;
// }
// if (!Snowflake::app()->isRun()) {
// break;
// }
// sleep(1);
// }
// return $server->stop($worker_id);
$receive = Coroutine::waitSignal($this->signal, -1);
while ($receive === true) {
if ($this->isPrint === false) {
$this->warning(sprintf('Receive %s#%d stop event.', $env, $worker_id));
$this->isPrint = true;
}
if (!Snowflake::app()->isRun()) {
break;
}
sleep(1);
}
return $server->stop($worker_id);
}