Ejemplo n.º 1
0
Archivo: Task.php Proyecto: eyehere/aha
 protected function _main()
 {
     $this->_objProtocolPackage->readPipe($this->_worker);
     $arrPackage = $this->_objProtocolPackage->getPackages();
     if (empty($arrPackage)) {
         return;
     }
     foreach ($arrPackage as $package) {
         $message = json_decode($package, true);
         $cmd = intval($message['cmd']);
         $coroutine = null;
         switch ($cmd) {
             case Constant::PACKAGE_TYPE_TASK:
                 $coroutine = $this->_doTask($message);
                 break;
             default:
                 Log::appLog()->warning(array(Monitor::KEY => Monitor::UNEXPECTED_ERR, '^package' => $package));
                 break;
         }
         Log::billLog()->debug(array('^package' => $package, 'type' => '_mainDistribute'));
         if ($coroutine instanceof \Generator) {
             $this->_objScheduler->newTask($coroutine);
             $this->_objScheduler->run();
         }
     }
     $this->_objScheduler->run();
 }
Ejemplo n.º 2
0
 public function next()
 {
     if (false !== $this->_line && is_resource($this->_fileHandle)) {
         $this->_line = fgets($this->_fileHandle);
         $this->_lineNo++;
     } elseif (count($this->_arrCity) > $this->_cityKey + 1) {
         if (is_resource($this->_fileHandle)) {
             fclose($this->_fileHandle);
         }
         while ($this->_cityKey <= count($this->_arrCity)) {
             $fileName = $this->_cityDir . $this->_arrCity[++$this->_cityKey];
             if (!file_exists($fileName) || !($this->_fileHandle = fopen($fileName, 'r'))) {
                 Log::appLog()->warning(array('cityFileNotFound' => $fileName));
                 continue;
             } else {
                 break;
             }
         }
         if ($this->_fileHandle) {
             fseek($this->_fileHandle, 0);
             $this->_line = fgets($this->_fileHandle);
         }
     }
     (yield true);
 }
Ejemplo n.º 3
0
 protected function _onAckProcess()
 {
     $this->_objProtocolPackage->readPipe($this->_worker);
     $arrPackage = $this->_objProtocolPackage->getPackages();
     if (empty($arrPackage)) {
         return AHA_AGAIN;
     }
     foreach ($arrPackage as $package) {
         $message = json_decode($package, true);
         $cmd = intval($message['cmd']);
         switch ($cmd) {
             case Constant::PACKAGE_TYPE_COMPLETE:
                 //来自distribute进程 通知drive进程继续发任务
                 //\Daemon\Library\Ipc\Shared::getMaxTaskNumAtomic()->sub(1);//在distribute进程减1有最短路径
                 break;
             default:
                 Log::appLog()->warning(array(Monitor::KEY => Monitor::UNEXPECTED_PACK, '%package' => $package));
                 break;
         }
         Log::billLog()->debug(array('%package' => $package, 'type' => 'onAckProcess'));
     }
     if ($this->_bolNeedTrigger) {
         $this->_bolNeedTrigger = false;
         $this->_onAckTrigger();
     }
     return AHA_AGAIN;
 }