modify
This commit is contained in:
@@ -26,6 +26,14 @@ class OnWorkerStart extends Callback
|
|||||||
private int $signal = SIGTERM | SIGKILL | SIGUSR2 | SIGUSR1;
|
private int $signal = SIGTERM | SIGKILL | SIGUSR2 | SIGUSR1;
|
||||||
|
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
Coroutine::set(['enable_deadlock_check' => false]);
|
||||||
|
|
||||||
|
$this->onSignal();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @param int $worker_id
|
* @param int $worker_id
|
||||||
@@ -36,18 +44,11 @@ class OnWorkerStart extends Callback
|
|||||||
*/
|
*/
|
||||||
public function onHandler(Server $server, int $worker_id): void
|
public function onHandler(Server $server, int $worker_id): void
|
||||||
{
|
{
|
||||||
$container['enable_deadlock_check'] = false;
|
|
||||||
// $container['exit_condition'] = function () {
|
|
||||||
// return Co::stats()['coroutine_num'] === 0;
|
|
||||||
// };
|
|
||||||
Coroutine::set($container);
|
|
||||||
|
|
||||||
$get_name = $this->get_process_name($server, $worker_id);
|
$get_name = $this->get_process_name($server, $worker_id);
|
||||||
if (!empty($get_name) && !Snowflake::isMac()) {
|
if (!empty($get_name) && !Snowflake::isMac()) {
|
||||||
swoole_set_process_name($get_name);
|
swoole_set_process_name($get_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->onSignal($server, $worker_id);
|
|
||||||
if ($worker_id >= $server->setting['worker_num']) {
|
if ($worker_id >= $server->setting['worker_num']) {
|
||||||
fire(Event::SERVER_TASK_START);
|
fire(Event::SERVER_TASK_START);
|
||||||
|
|
||||||
@@ -64,19 +65,17 @@ class OnWorkerStart extends Callback
|
|||||||
* @param $server
|
* @param $server
|
||||||
* @param $worker_id
|
* @param $worker_id
|
||||||
*/
|
*/
|
||||||
public function onSignal($server, $worker_id)
|
public function onSignal()
|
||||||
{
|
{
|
||||||
$this->debug(sprintf(workerName($worker_id) . ' #%d is start.....', $worker_id));
|
Coroutine\go(function () {
|
||||||
Coroutine\go(function (Server $server, $worker_id) {
|
|
||||||
if (!Coroutine::waitSignal($this->signal)) {
|
if (!Coroutine::waitSignal($this->signal)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
while (Snowflake::app()->isRun()) {
|
while (Snowflake::app()->isRun()) {
|
||||||
var_dump(Snowflake::app()->isRun());
|
|
||||||
Coroutine::sleep(1);
|
Coroutine::sleep(1);
|
||||||
}
|
}
|
||||||
return $server->stop($worker_id, true);
|
return Snowflake::app()->getSwoole()->stop();
|
||||||
}, $server, $worker_id);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user