File tree Expand file tree Collapse file tree 2 files changed +9
-36
lines changed Expand file tree Collapse file tree 2 files changed +9
-36
lines changed Original file line number Diff line number Diff line change @@ -528,27 +528,23 @@ public function getExcelData($fileName)
528
528
*
529
529
* @param $excel_id
530
530
*
531
- * @return string
531
+ * @return string|bool
532
532
*/
533
533
public function completionRate ($ excel_id )
534
534
{
535
535
if ($ api_excel = ApiExcel::find ($ excel_id )) {
536
536
if ($ api_excel ['state ' ] == 1 ) {
537
- $ total_excel = cacheTotalExcel ($ excel_id , $ api_excel ['upload_url ' ]);
537
+ $ total_excel = cacheTotalExcel ($ excel_id , public_path ( $ api_excel ['upload_url ' ]) );
538
538
if ($ total_excel > 0 ) {
539
539
// 2. 查询 api_excel_logs 表更新的数据量
540
540
$ total = ApiExcelLogs::where ('api_excel_id ' , $ excel_id )->count ();
541
541
// 3. 返回完成率
542
- return floor ($ total / $ api_excel ['total_excel ' ] * 100 ).'% ' ;
543
- } else {
544
- return '100% ' ;
542
+ return floor ($ total / $ api_excel ['total_excel ' ] * 100 );
545
543
}
546
- } else {
547
- return '' ;
548
544
}
549
- } else {
550
- return '100% ' ;
551
545
}
546
+
547
+ return '100 ' ;
552
548
}
553
549
554
550
/**
Original file line number Diff line number Diff line change @@ -37,40 +37,17 @@ public function onOpen($server, $request)
37
37
while (true ) {
38
38
// 3. 输出完成率
39
39
$ rate = MultithreadingRepository::getInstent ()->completionRate ($ req ['id ' ]);
40
- $ server ->push ($ request ->fd , $ rate );
40
+ $ server ->push ($ request ->fd , $ rate. ' % ' );
41
41
sleep (3 );
42
- if ($ rate ) {
43
- break ;
44
- }
45
- }
46
- }
47
42
48
-
49
- if (isset ($ req ['id ' ]) && $ api_excel = ApiExcel::find ($ req ['id ' ])) {
50
- if ($ api_excel ['state ' ] == 1 ) {
51
- $ total_excel = cacheTotalExcel ($ req ['id ' ], $ api_excel ['upload_url ' ]);
52
- if ($ total_excel > 0 ) {
53
- // 2. 查询 api_excel_logs 表更新的数据量
54
- while (true ) {
55
- $ total = ApiExcelLogs::where ('api_excel_id ' , $ req ['id ' ])->count ();
56
- $ str = floor ($ total / $ api_excel ['total_excel ' ] * 100 ).'% ' ;
57
- // 3. 输出完成率
58
- $ server ->push ($ request ->fd , $ str );
59
- sleep (3 );
60
- if ($ total >= $ api_excel ['total_excel ' ]) {
61
- break ;
62
- }
63
- }
64
- } else {
65
- $ server ->push ($ request ->fd , '100% ' );
43
+ if ($ rate >= 100 ) {
44
+ break ;
66
45
}
67
-
68
- } else {
69
- $ server ->push ($ request ->fd , '0% ' );
70
46
}
71
47
} else {
72
48
$ server ->push ($ request ->fd , '100% ' );
73
49
}
50
+
74
51
// throw new \Exception('an exception');// 此时抛出的异常上层会忽略,并记录到Swoole日志,需要开发者try/catch捕获处理
75
52
}
76
53
You can’t perform that action at this time.
0 commit comments