Skip to content

Commit 92adfb4

Browse files
committed
fix: 任务完成后再输出客户端一次结果
1 parent 86423c4 commit 92adfb4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

laravel/app/Services/WebSocketService.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ public function onOpen($server, $request)
4646

4747
$action = $req['action'] ?? '';
4848
switch ($action) {
49-
case 'api_excel':
49+
case 'api_excel': // api_excel 列表完成率
5050
while (true) {
51-
$data = $this->apiExcel();
52-
$server->push($request->fd, $data);
51+
$user_id = auth('api')->user()['id'];
52+
$server->push($request->fd, $this->apiExcel($user_id));
5353
sleep(5);
5454
$state = ApiExcel::where('state', 1)->first();
5555
if (!$state) {
56+
$server->push($request->fd, $this->apiExcel($user_id));
5657
break;
5758
}
5859
// 每个用户 fd 限制请求次数
@@ -65,7 +66,7 @@ public function onOpen($server, $request)
6566
$count = $this->redis->incr($redisKey);
6667
if ($count == 1) {
6768
// 设置过期时间
68-
$this->redis->expire($redisKey, 600);
69+
$this->redis->expire($redisKey, 6000);
6970
}
7071
if ($count > 200) { // 防止刷单的安全拦截
7172
break; // 超出就跳出循环
@@ -137,12 +138,12 @@ protected function getRateById($id)
137138
/**
138139
* 获取api_excel 列表-完成率
139140
*
141+
* @param int $user_id 用户 id
142+
*
140143
* @return array
141144
*/
142-
private function apiExcel()
145+
private function apiExcel($user_id)
143146
{
144-
$user_id = auth('api')->user()['id'];
145-
146147
// 查询对应用户的上传数据
147148
$where = [];
148149
if ($user_id != 1) {

0 commit comments

Comments
 (0)