This commit is contained in:
as2252258@163.com
2021-03-01 00:55:31 +08:00
parent d56bd0527b
commit 55109fa64d
2 changed files with 36 additions and 32 deletions
+36
View File
@@ -13,9 +13,22 @@ use Swoole\Coroutine;
use Swoole\Process;
use Swoole\Server;
/**
* Class OnManagerStart
* @package HttpServer\Events
*/
class OnManagerStart extends Callback
{
/** @var int|string 重启信号 */
private int $signal = SIGUSR1 | SIGUSR2;
/** @var bool 是否打印 */
private bool $isPrint = false;
/**
* @param Server $server
* @throws Exception
@@ -31,6 +44,29 @@ class OnManagerStart extends Callback
return;
}
name(Config::get('id', false, 'system') . ' Server Manager.');
Coroutine\go([$this, 'onSignal'], $server);
}
/**
* @param $server
* @param $worker_id
*/
public function onSignal($server)
{
$receive = Coroutine::waitSignal($this->signal, 30);
while ($receive === true) {
if ($this->isPrint === false) {
$this->warning(sprintf('Receive Worker stop event.'));
$this->isPrint = true;
}
if (!Snowflake::app()->isRun()) {
break;
}
sleep(1);
}
return $server->stop();
}
}