Skip to content

Commit 52ed6df

Browse files
committed
fix(task): debug 记录日志
1 parent 507de38 commit 52ed6df

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

laravel/app/Http/Repository/MultithreadingRepository.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace App\Http\Repository;
1010

1111

12+
use App\Models\ApiExcelLogs;
1213
use GuzzleHttp\Pool;
1314
use GuzzleHttp\Client;
1415
use Illuminate\Support\Facades\Log;
@@ -27,6 +28,7 @@ class MultithreadingRepository
2728
*/
2829
public $data = [];
2930

31+
public $api_excel_id = 0;
3032
public $fileName;
3133
public $config;
3234

@@ -53,6 +55,11 @@ public static function getInstent()
5355
return self::$instance;
5456
}
5557

58+
public function setApiExcelId($id)
59+
{
60+
$this->api_excel_id = $id;
61+
}
62+
5663
/**
5764
* 设置参数
5865
*
@@ -297,12 +304,30 @@ public function newRequest($url, $appkey)
297304
'fulfilled' => function($response, $index) {
298305
// this is delivered each successful response
299306
$result = $response->getBody()->getContents();
300-
Log::info($index.'-result', ['result' => $result]);
307+
// 记录返回数据到数据库 api_excel_logs 中
308+
$para = array_values($this->dataSet['data'][$index]);
309+
$logs = [
310+
'api_excel_id' => $this->api_excel_id,
311+
'sort_index' => $index,
312+
'param' => implode('|', $para),
313+
'result' => $result,
314+
'created_at' => date('Y-m-d H:i:s'),
315+
];
316+
ApiExcelLogs::insert($logs);
301317
// var_dump($result);
302318
// var_dump($index);
303319
$this->data[$index] = $result;
304320
},
305321
'rejected' => function($reason, $index) {
322+
$para = array_values($this->dataSet['data'][$index]);
323+
$logs = [
324+
'api_excel_id' => $this->api_excel_id,
325+
'sort_index' => $index,
326+
'param' => implode('|', $para),
327+
'result' => '',
328+
'created_at' => date('Y-m-d H:i:s'),
329+
];
330+
ApiExcelLogs::insert($logs);
306331
// this is delivered each failed request
307332
if (is_object($reason) && is_callable([$reason, 'getMessage'])) {
308333
$reason = 'Line:'.$reason->getLine().' in '.$reason->getFile().'; Message: '.$reason->getMessage();

laravel/app/Listeners/ApiExcelListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function handle(ApiExcelEvent $event)
5858
$param = $apiExcel->apiParam()->first();
5959
if ($param) {
6060
$multi = MultithreadingRepository::getInstent();
61+
$multi->setApiExcelId($data['id']);
6162
$multi->setParam($path, ['concurrent' => $apiExcel->concurrent]);
6263
$result = $multi->newMultiRequest($param->url, $apiExcel->appkey);
6364

0 commit comments

Comments
 (0)