Exemple #1
0
 protected function _taskWorkerComplete($package)
 {
     $pid = $package['content']['pid'];
     $res = \Daemon\Library\Ipc\Shared::getCurrentTaskTable()->decr($pid, 'taskNum', 1);
     if (false === $res) {
         Log::monitor()->error(array(Monitor::KEY => Monitor::TABLE_DECR_ERR, '#package' => $package));
     }
     $driveWorker = $this->_objManager->getDriveWorker();
     list($drivePid, $driveProcess) = each($driveWorker);
     $ret = $driveProcess->write(json_encode($package) . Constant::PACKAGE_EOF);
     if (false === $ret) {
         Log::monitor()->error(array(Monitor::KEY => Monitor::IPC_PIPE_WRITE_ERR, '#package' => $package));
         Log::redoLog(array('redo' => $package));
         return false;
     }
     Log::billLog()->debug(array('#package' => $package, 'type' => 'complete'));
     return true;
 }
Exemple #2
0
 protected function _waitChildProcess()
 {
     //必须为false,非阻塞模式
     //信号发生时可能同时有多个子进程退出
     //必须循环执行wait直到返回false
     $objManager = \Daemon\Library\Ipc\Manager::getInstance();
     while ($result = \swoole_process::wait(false)) {
         $pid = $result['pid'];
         if ($objManager->hasDriveWorker($pid)) {
             $objManager->delDriveWorker($pid);
             \Daemon\Library\Ipc\Shared::delCurrentTaskTable($pid);
             if (!$this->_sigterm) {
                 $objManager->createDriveWorker(\Daemon\Process\Master::getInstance()->getAha(), 1);
             }
         } elseif ($objManager->hasTaskWorker($pid)) {
             $objManager->delTaskWorker($pid);
             \Daemon\Library\Ipc\Shared::delCurrentTaskTable($pid);
             if (!$this->_sigterm) {
                 $objManager->createDirtributeWorker(\Daemon\Process\Master::getInstance()->getAha(), 1);
             }
         } elseif ($objManager->hasRedoWorker($pid)) {
             $objManager->delRedoWorker($pid);
             \Daemon\Library\Ipc\Shared::delCurrentTaskTable($pid);
             if (!$this->_sigterm) {
                 $objManager->createRedoWorker(\Daemon\Process\Master::getInstance()->getAha(), 1);
             }
         } elseif ($objManager->hasStatsWorker($pid)) {
             $objManager->delStatsWorker($pid);
             \Daemon\Library\Ipc\Shared::delCurrentTaskTable($pid);
             if (!$this->_sigterm) {
                 $objManager->createStatsWorker(\Daemon\Process\Master::getInstance()->getAha(), 1);
             }
         } else {
         }
     }
     //如果是SIGTERM信号 并且子进程都已经退出了 父进程终止
     $workers = \Daemon\Library\Ipc\Shared::getCurrentTaskTable();
     if ($this->_sigterm && !$workers->count()) {
         \swoole_event_exit();
     }
 }