debug
This commit is contained in:
@@ -261,33 +261,38 @@ class Site
|
||||
$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') {
|
||||
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');
|
||||
$this->redisDailyInc($incKey);
|
||||
// Cache::store('redis')->inc($incKey);
|
||||
$ChapterPage = $this->getChapterPage($this, $arrFilter[$intKey]['uri']);
|
||||
$ChapterPage->setContent($strContent);
|
||||
$ChapterPage->setData($arrFilter[$intKey]);
|
||||
|
||||
$arrChapterPage[] = $ChapterPage;
|
||||
|
||||
// 成功指标
|
||||
$this->redisDailyInc(config('task.app_name') . '_success_getChapterPageList:' . date('Y-m-d'));
|
||||
|
||||
} elseif ($arrResult['state'] === 'rejected') {
|
||||
$this->redisDailyInc(config('task.app_name') . '_errer_getChapterPageList:' . date('Y-m-d'));
|
||||
|
||||
} 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';
|
||||
$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']);
|
||||
@@ -295,23 +300,69 @@ class Site
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
// /** @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