This commit is contained in:
2021-03-04 10:50:05 +08:00
parent bfee7ca962
commit 2bf341d23d
+9 -5
View File
@@ -40,12 +40,11 @@ class OnWorkerStart extends Callback
annotation()->read(APP_PATH . 'app', 'App');
$this->debug(sprintf('scan app dir use time %s', microtime(true) - $start));
$prefix = sprintf('%s #%d Pid:%d start.', ucfirst(env('environmental')), $worker_id, $server->worker_pid);
if ($worker_id >= $server->setting['worker_num']) {
$this->onTask($server, $worker_id, $prefix);
$this->onTask($server, $worker_id);
} else {
$this->onWorker($server, $worker_id, $prefix);
$this->onWorker($server, $worker_id);
}
}
@@ -57,10 +56,12 @@ class OnWorkerStart extends Callback
* @throws ComponentException
* @throws ConfigException
*/
public function onTask(Server $server, int $worker_id, $prefix)
public function onTask(Server $server, int $worker_id)
{
putenv('environmental=' . Snowflake::TASK);
$prefix = sprintf('%s #%d Pid:%d start.', ucfirst(env('environmental')), $worker_id, $server->worker_pid);
$start = microtime(true);
fire(Event::SERVER_TASK_START);
@@ -78,10 +79,13 @@ class OnWorkerStart extends Callback
* @throws ConfigException
* @throws Exception
*/
public function onWorker(Server $server, int $worker_id, $prefix)
public function onWorker(Server $server, int $worker_id)
{
Snowflake::setWorkerId($server->worker_pid);
putenv('environmental=' . Snowflake::WORKER);
$prefix = sprintf('%s #%d Pid:%d start.', ucfirst(env('environmental')), $worker_id, $server->worker_pid);
try {
$start = microtime(true);
fire(Event::SERVER_WORKER_START, [$worker_id]);