This commit is contained in:
as2252258@163.com
2021-02-27 04:48:44 +08:00
parent 2c7e938b9f
commit ac10d10b9d
2 changed files with 485 additions and 466 deletions
+20 -10
View File
@@ -42,11 +42,31 @@ class OnWorkerStart extends Callback
// return Coroutine::stats()['coroutine_num'] === 0; // return Coroutine::stats()['coroutine_num'] === 0;
// } // }
// ]); // ]);
putenv('workerId=' . $worker_id);
$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);
$this->debug(sprintf(workerName($worker_id) . ' #%d is start.....', $worker_id));
if ($worker_id >= $server->setting['worker_num']) {
fire(Event::SERVER_TASK_START);
} else {
Snowflake::setWorkerId($server->worker_pid);
$this->setWorkerAction($worker_id);
}
}
/**
* @param $server
* @param $worker_id
*/
public function onSignal($server, $worker_id)
{
Coroutine\go(function (Server $server, $worker_id) { Coroutine\go(function (Server $server, $worker_id) {
$sigkill = Coroutine::waitSignal(SIGTERM | SIGKILL | SIGUSR2 | SIGUSR1); $sigkill = Coroutine::waitSignal(SIGTERM | SIGKILL | SIGUSR2 | SIGUSR1);
if ($sigkill !== false) { if ($sigkill !== false) {
@@ -61,16 +81,6 @@ class OnWorkerStart extends Callback
} while (true); } while (true);
return Process::kill($server->worker_pid); return Process::kill($server->worker_pid);
}, $server, $worker_id); }, $server, $worker_id);
$name = ($worker_id >= $server->setting['worker_num'] ? 'Task' : 'Worker');
$this->debug(sprintf($name . ' #%d is start.....', $worker_id));
putenv('workerId=' . $name . '.' . $worker_id);
if ($worker_id >= $server->setting['worker_num']) {
fire(Event::SERVER_TASK_START);
} else {
Snowflake::setWorkerId($server->worker_pid);
$this->setWorkerAction($worker_id);
}
} }
+9
View File
@@ -38,6 +38,15 @@ if (!function_exists('make')) {
} }
if (!function_exists('workerName')) {
function workerName($worker_id)
{
return $worker_id >= Snowflake::app()->getSwoole()->setting['worker_num'] ? 'Task' : 'Worker';
}
}
if (!function_exists('annotation')) { if (!function_exists('annotation')) {