/** * Job执行逻辑 */ public function handle_request() { printf('[%s] lastLogId: %s' . PHP_EOL, date('Y-m-d H:i:s'), $this->lastLogId); $this->setLog(sprintf('[%s] lastLogId: %s' . PHP_EOL, date('Y-m-d H:i:s'), $this->lastLogId)); // 获取非删除的房子 $params = array(array('isDelete', '=', 0), array('id', '>', $this->lastLogId)); if ($this->cityIds) { $params = array(array('isDelete', '=', 0), array('cityId', 'in', $this->cityIds), array('id', '>', $this->lastLogId)); } $tasks = Model_House_JpHouseIdx::getPropLists($params, $this->limit); if ($tasks === false) { $this->setLog(sprintf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '获取数据失败')); exit; } if (empty($tasks)) { // 任务完成 printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '任务执行完成'); $this->setStop(); $this->setShStopFlag(); $this->setFlag(array('lastLogId' => 0)); exit; } $doProps = array(); /** 本次处理的房子 */ $doTmpProIds = array(); $solrProIdsTmp = array(); $solrProIds = array(); foreach ($tasks as $task) { $this->lastLogId = $task['id']; $doProps[$task['id']] = $task; $doTmpProIds[$task['houseType']][] = $task['id']; } foreach ($doTmpProIds as $type => $proIds) { printf('[%s] 获取solr, type: %s, proId: %s' . PHP_EOL, date('Y-m-d H:i:s'), $type, json_encode($proIds)); // 获取solr $solrs = Util_SearchUtil::getJpPropsFromSolr($this->getTypeByHouseType($type), $proIds, $this->limit); if (!empty($solrs)) { $solrProIdsTmp[$type] = $solrs; } } // 扁平处理 if (!empty($solrProIdsTmp)) { foreach ($solrProIdsTmp as $items) { foreach ($items as $item) { $solrProIds[] = $item['id']; } } } // 拿出不在线的进行处理 $willDealProIds = array_diff(array_keys($doProps), $solrProIds); if (empty($willDealProIds)) { printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '本轮取的房子都在线,不需要处理'); //记录游标 $this->setFlag(array('lastLogId' => $this->lastLogId)); die; } // 循环处理任务 foreach ($willDealProIds as $willDealProId) { $this->dealTask($doProps[$willDealProId]); } //记录游标 $this->setFlag(array('lastLogId' => $this->lastLogId)); }