コード例 #1
0
 /**
  * Job执行逻辑
  */
 public function handle_request()
 {
     printf('[%s] lastLogId: %s, start: %s, end: %s' . PHP_EOL, date('Y-m-d H:i:s'), $this->lastLogId, $this->start, $this->end);
     // 获取任务
     $changeList = Bll_Broker_BrokerLimit::getChangeLogList($this->lastLogId, $this->start, $this->end, $this->limit);
     if ($changeList === false) {
         //记录返回值
         printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '获取数据失败');
         exit;
     }
     if (empty($changeList)) {
         // 昨天任务完成
         printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '任务执行完成');
         $this->setStop();
         $this->setShStopFlag();
         exit;
     }
     // 循环任务处理
     foreach ($changeList as $change) {
         $result = $this->dealTask($change['userOrBrokerId']);
         $this->lastLogId = $change['id'];
         // 打印处理过程日志
         $msgs = $result['msg'];
         if (is_array($msgs)) {
             foreach ($msgs as $msg) {
                 if (!empty($msg)) {
                     if (is_array($msg)) {
                         print_r($msg);
                     } else {
                         echo $msg . PHP_EOL;
                     }
                 }
             }
         } else {
             if (!empty($msgs)) {
                 if (is_array($msgs)) {
                     print_r($msg);
                 } else {
                     echo $msgs . PHP_EOL;
                 }
             }
         }
     }
     //记录游标
     $this->setFlag(array('lastLogId' => $this->lastLogId));
 }