Commit efd84316 authored by Liu lu's avatar Liu lu

优化日志记录

parent 21452074
...@@ -106,7 +106,7 @@ class LogTraceHandler ...@@ -106,7 +106,7 @@ class LogTraceHandler
}else if (is_string($track)||is_numeric($track)) { }else if (is_string($track)||is_numeric($track)) {
$logInfo = $track; $logInfo = $track;
}else{ }else{
$logInfo = print_r($track, true); $logInfo = json_encode($track,JSON_PRETTY_PRINT); ;//print_r($track, true);
} }
$logInfo .= "\n\n"; $logInfo .= "\n\n";
......
...@@ -72,8 +72,6 @@ abstract class RedisQueueBatchHandler ...@@ -72,8 +72,6 @@ abstract class RedisQueueBatchHandler
//每次从列表取100 //每次从列表取100
$arr = $this->redis->lRange($this->queue_name,0,self::BATCH_DEAL_NUM-1); $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){ $formatArr = array_map(function ($item){
return json_decode($item,true); return json_decode($item,true);
...@@ -81,15 +79,17 @@ abstract class RedisQueueBatchHandler ...@@ -81,15 +79,17 @@ abstract class RedisQueueBatchHandler
try { try {
//具体批处理逻辑 //具体批处理逻辑
$this->batchDeal($formatArr); $this->batchDeal($formatArr);
//取完 从队列删掉
$this->redis->lTrim($this->queue_name,count($arr),-1);
}catch (\Throwable $exception){ }catch (\Throwable $exception){
//错误码为100 重新推到队列 //错误码为100 重新推到队列
if($exception->getCode()==self::ERROR_RETRY_CODE){ if($exception->getCode()==self::ERROR_RETRY_CODE){
if($this->retry<self::MAX_RETRY_TIMES){ //重试次数不超过3次 if($this->retry<self::MAX_RETRY_TIMES){ //重试次数不超过3次
$this->backToQueue($arr); //$this->backToQueue($arr);
$this->retry++; $this->retry++;
}else{ }else{
$this->redis->lTrim($this->queue_name,count($arr),-1);
$this->retry = 0; //重置当前次数 $this->retry = 0; //重置当前次数
$this->errorWriteToFile($formatArr,$exception); $this->errorWriteToFile($formatArr,$exception);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment