Commit efd84316 authored by Liu lu's avatar Liu lu
Browse files

优化日志记录

parent 21452074
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ class LogTraceHandler
        }else if (is_string($track)||is_numeric($track)) {
            $logInfo = $track;
        }else{
            $logInfo = print_r($track, true);
            $logInfo =  json_encode($track,JSON_PRETTY_PRINT); ;//print_r($track, true);
        }
        $logInfo .=  "\n\n";

+4 −4
Original line number Diff line number Diff line
@@ -72,8 +72,6 @@ abstract class RedisQueueBatchHandler
            //每次从列表取100
            $arr = $this->redis->lRange($this->queue_name,0,self::BATCH_DEAL_NUM-1);

            //取完 从队列删掉
            $this->redis->lTrim($this->queue_name,count($arr),-1);
            //数据格式化
            $formatArr = array_map(function ($item){
                return json_decode($item,true);
@@ -81,15 +79,17 @@ abstract class RedisQueueBatchHandler
            try {
                //具体批处理逻辑
                $this->batchDeal($formatArr);

                //取完 从队列删掉
                $this->redis->lTrim($this->queue_name,count($arr),-1);
            }catch (\Throwable $exception){

                //错误码为100 重新推到队列
                if($exception->getCode()==self::ERROR_RETRY_CODE){
                    if($this->retry<self::MAX_RETRY_TIMES){ //重试次数不超过3次
                        $this->backToQueue($arr);
                        //$this->backToQueue($arr);
                        $this->retry++;
                    }else{
                        $this->redis->lTrim($this->queue_name,count($arr),-1);
                        $this->retry = 0; //重置当前次数
                        $this->errorWriteToFile($formatArr,$exception);
                    }