代码优化
This commit is contained in:
@@ -196,8 +196,8 @@ class WorkbenchJob
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将好友列表分成20组
|
// 将好友列表分成10组
|
||||||
$friendGroups = array_chunk($friendList, 20);
|
$friendGroups = array_chunk($friendList, 10);
|
||||||
$processes = [];
|
$processes = [];
|
||||||
|
|
||||||
foreach ($friendGroups as $groupIndex => $friendGroup) {
|
foreach ($friendGroups as $groupIndex => $friendGroup) {
|
||||||
@@ -214,6 +214,10 @@ class WorkbenchJob
|
|||||||
} else {
|
} else {
|
||||||
// 子进程
|
// 子进程
|
||||||
try {
|
try {
|
||||||
|
// 重置数据库连接
|
||||||
|
Db::close();
|
||||||
|
Db::init();
|
||||||
|
|
||||||
foreach ($friendGroup as $friend) {
|
foreach ($friendGroup as $friend) {
|
||||||
// 验证是否达到点赞次数上限
|
// 验证是否达到点赞次数上限
|
||||||
$likeCount = $this->getTodayLikeCount($workbench, $config, $friend['deviceId']);
|
$likeCount = $this->getTodayLikeCount($workbench, $config, $friend['deviceId']);
|
||||||
@@ -234,6 +238,9 @@ class WorkbenchJob
|
|||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error("工作台 {$workbench->id} 子进程异常: " . $e->getMessage());
|
Log::error("工作台 {$workbench->id} 子进程异常: " . $e->getMessage());
|
||||||
|
} finally {
|
||||||
|
// 确保关闭数据库连接
|
||||||
|
Db::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 子进程执行完毕后退出
|
// 子进程执行完毕后退出
|
||||||
|
|||||||
Reference in New Issue
Block a user