getAnnotation(); $annotation->setLoader(unserialize(file_get_contents(storage('runtime.php')))); if ($worker_id < $server->setting['worker_num']) { $this->onWorker($server, $annotation); } else { $this->onTask($server, $annotation); } } /** * @param Server $server * @param int $worker_id * @return bool */ private function isWorker($server, int $worker_id): bool { return $worker_id < $server->setting['worker_num']; } /** * @param Server $server * @param int $worker_id * @throws Exception */ public function onTask(Server $server, Annotation $annotation) { $annotation->runtime(MODEL_PATH); putenv('environmental=' . Snowflake::TASK); Snowflake::setTaskId($server->worker_pid); fire(Event::SERVER_TASK_START); } /** * @param Server $server * @param int $worker_id * @throws Exception */ public function onWorker(Server $server, Annotation $annotation) { try { $annotation->runtime(CONTROLLER_PATH); $annotation->runtime(APP_PATH, CONTROLLER_PATH); Snowflake::setWorkerId($server->worker_pid); putenv('environmental=' . Snowflake::WORKER); fire(Event::SERVER_WORKER_START, [getenv('worker')]); } catch (\Throwable $exception) { $this->addError($exception, 'throwable'); write($exception->getMessage(), 'worker'); } } }