debug
This commit is contained in:
@@ -261,57 +261,108 @@ class Site
|
|||||||
$arrChapterPage = [];
|
$arrChapterPage = [];
|
||||||
|
|
||||||
$arrPromises = [];
|
$arrPromises = [];
|
||||||
$arrSuccessfulResults = [];
|
|
||||||
|
|
||||||
foreach ($arrFilter as $intKey => $arrItem) {
|
foreach ($arrFilter as $intKey => $arrItem) {
|
||||||
$arrPromises[$intKey] = $this->getClient()->getAsync($arrItem['uri']);
|
$arrPromises[$intKey] = $this->getClient()->getAsync($arrItem['uri']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$arrResults = Promise\Utils::settle($arrPromises)->wait();
|
$arrResults = Promise\Utils::settle($arrPromises)->wait();
|
||||||
|
|
||||||
// $arrSuccessfulResults = array_filter($arrResults, function ($arrResult) {
|
|
||||||
// return $arrResult['state'] === 'fulfilled';
|
|
||||||
// });
|
|
||||||
foreach ($arrResults as $intKey => $arrResult) {
|
foreach ($arrResults as $intKey => $arrResult) {
|
||||||
if ($arrResult['state'] == 'fulfilled') {
|
if ($arrResult['state'] === 'fulfilled') {
|
||||||
|
$Response = $arrResult['value'];
|
||||||
|
$strContent = $Response->getBody()->getContents();
|
||||||
|
|
||||||
$arrSuccessfulResults[$intKey] = $arrResult;
|
// 跳过空内容
|
||||||
|
if (empty($strContent)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$incKey = config('task.app_name').'_success_getChapterPageList:' . date('Y-m-d');
|
$ChapterPage = $this->getChapterPage($this, $arrFilter[$intKey]['uri']);
|
||||||
$this->redisDailyInc($incKey);
|
$ChapterPage->setContent($strContent);
|
||||||
// Cache::store('redis')->inc($incKey);
|
$ChapterPage->setData($arrFilter[$intKey]);
|
||||||
|
|
||||||
} elseif ($arrResult['state'] == 'rejected') {
|
$arrChapterPage[] = $ChapterPage;
|
||||||
$incKey = config('task.app_name').'_errer_getChapterPageList:' . date('Y-m-d');
|
|
||||||
$this->redisDailyInc($incKey);
|
// 成功指标
|
||||||
// Cache::store('redis')->inc($incKey);
|
$this->redisDailyInc(config('task.app_name') . '_success_getChapterPageList:' . date('Y-m-d'));
|
||||||
if(config('log.task_debug_log_open_status')){
|
|
||||||
// 记录失败原因
|
} elseif ($arrResult['state'] === 'rejected') {
|
||||||
$reason = $arrResult['reason'] instanceof \Exception ? $arrResult['reason']->getMessage() : 'Unknown error';
|
$this->redisDailyInc(config('task.app_name') . '_errer_getChapterPageList:' . date('Y-m-d'));
|
||||||
|
|
||||||
|
if (config('log.task_debug_log_open_status')) {
|
||||||
|
$reason = $arrResult['reason'] instanceof \Exception
|
||||||
|
? $arrResult['reason']->getMessage()
|
||||||
|
: 'Unknown error';
|
||||||
$strUri = $arrFilter[$intKey]['uri'] ?? '';
|
$strUri = $arrFilter[$intKey]['uri'] ?? '';
|
||||||
\think\facade\Log::error("Request failed for getNovelChapterInfo , URI: {$strUri }, Reason: {$reason}");
|
\think\facade\Log::error("Request failed for getNovelChapterInfo, URI: {$strUri}, Reason: {$reason}");
|
||||||
var_dump($strUri .' => '.$arrResult['state']);
|
var_dump($strUri . ' => ' . $arrResult['state']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($arrSuccessfulResults as $intKey => $arrResult) {
|
|
||||||
$Response = $arrResult['value'];
|
|
||||||
|
|
||||||
$strContent = $Response->getBody()->getContents();;
|
|
||||||
|
|
||||||
$ChapterPage = $this->getChapterPage($this, $arrFilter[$intKey]['uri']);
|
|
||||||
|
|
||||||
$ChapterPage->setContent($strContent);
|
|
||||||
$ChapterPage->setData($arrFilter[$intKey]);
|
|
||||||
|
|
||||||
$arrChapterPage[] = $ChapterPage;
|
|
||||||
|
|
||||||
$incKey = config('task.app_name').'_success_quit_getChapterPageList:' . date('Y-m-d');
|
|
||||||
$this->redisDailyInc($incKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $arrChapterPage;
|
return $arrChapterPage;
|
||||||
|
|
||||||
|
|
||||||
|
// /** @var ChapterPage[] */
|
||||||
|
// $arrChapterPage = [];
|
||||||
|
|
||||||
|
// $arrPromises = [];
|
||||||
|
// $arrSuccessfulResults = [];
|
||||||
|
|
||||||
|
// foreach ($arrFilter as $intKey => $arrItem) {
|
||||||
|
// $arrPromises[$intKey] = $this->getClient()->getAsync($arrItem['uri']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $arrResults = Promise\Utils::settle($arrPromises)->wait();
|
||||||
|
|
||||||
|
// // $arrSuccessfulResults = array_filter($arrResults, function ($arrResult) {
|
||||||
|
// // return $arrResult['state'] === 'fulfilled';
|
||||||
|
// // });
|
||||||
|
// foreach ($arrResults as $intKey => $arrResult) {
|
||||||
|
// if ($arrResult['state'] == 'fulfilled') {
|
||||||
|
|
||||||
|
// $arrSuccessfulResults[$intKey] = $arrResult;
|
||||||
|
|
||||||
|
// $incKey = config('task.app_name').'_success_getChapterPageList:' . date('Y-m-d');
|
||||||
|
// $this->redisDailyInc($incKey);
|
||||||
|
// // Cache::store('redis')->inc($incKey);
|
||||||
|
|
||||||
|
// } elseif ($arrResult['state'] == 'rejected') {
|
||||||
|
// $incKey = config('task.app_name').'_errer_getChapterPageList:' . date('Y-m-d');
|
||||||
|
// $this->redisDailyInc($incKey);
|
||||||
|
// // Cache::store('redis')->inc($incKey);
|
||||||
|
// if(config('log.task_debug_log_open_status')){
|
||||||
|
// // 记录失败原因
|
||||||
|
// $reason = $arrResult['reason'] instanceof \Exception ? $arrResult['reason']->getMessage() : 'Unknown error';
|
||||||
|
// $strUri = $arrFilter[$intKey]['uri'] ?? '';
|
||||||
|
// \think\facade\Log::error("Request failed for getNovelChapterInfo , URI: {$strUri }, Reason: {$reason}");
|
||||||
|
// var_dump($strUri .' => '.$arrResult['state']);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// foreach ($arrSuccessfulResults as $intKey => $arrResult) {
|
||||||
|
// $Response = $arrResult['value'];
|
||||||
|
|
||||||
|
// $strContent = $Response->getBody()->getContents();
|
||||||
|
|
||||||
|
// // ✳️ 如果响应内容为空或无效,跳过(你可以根据规则自行扩展)
|
||||||
|
// if (empty($strContent)) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $ChapterPage = $this->getChapterPage($this, $arrFilter[$intKey]['uri']);
|
||||||
|
|
||||||
|
// $ChapterPage->setContent($strContent);
|
||||||
|
// $ChapterPage->setData($arrFilter[$intKey]);
|
||||||
|
|
||||||
|
// $arrChapterPage[] = $ChapterPage;
|
||||||
|
|
||||||
|
// $incKey = config('task.app_name').'_success_quit_getChapterPageList:' . date('Y-m-d');
|
||||||
|
// $this->redisDailyInc($incKey);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return $arrChapterPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user