|
11 | 11 |
|
12 | 12 | use App\Models\ApiExcel;
|
13 | 13 | use App\Models\ApiExcelLogs;
|
| 14 | +use Illuminate\Support\Facades\DB; |
14 | 15 |
|
15 | 16 | class ApiRepository
|
16 | 17 | {
|
@@ -70,14 +71,30 @@ public function handleAutoDelete()
|
70 | 71 | public function autoFailed()
|
71 | 72 | {
|
72 | 73 | // 查询数据库已完成的任务,判断过期条件
|
73 |
| - $excels = ApiExcel::where('state', 1)->get(['id', 'auto_delete', 'created_at', 'updated_at']); |
| 74 | + // $excels = ApiExcel::where('state', 1)->get(['id', 'auto_delete', 'created_at', 'updated_at']); |
| 75 | + |
| 76 | + // New: 2020-05-31 失败任务的条件 |
| 77 | + // 1. 完成率 96% -- 5 秒不再增加 |
| 78 | + // 2. 完成率 50% -- 1 分钟不再增加 |
| 79 | + // 3. 完成率 10% -- 5 分钟不再增加 |
| 80 | + // 4. 完成率 1% -- 10 分钟不再增加 |
| 81 | + $excels = DB::connection()->select('SELECT ae.id,ae.api_param_id,ae.state,ae.total_excel,ael.api_excel_id,ael.sort_index,ael.created_at FROM `boss_api_excel` ae LEFT JOIN boss_api_excel_logs ael ON ae.id=ael.api_excel_id AND ael.id=(SELECT c.id FROM boss_api_excel_logs c WHERE ael.api_excel_id=c.api_excel_id ORDER BY sort_index DESC LIMIT 1) |
| 82 | +WHERE ae.state=1 AND ae.`deleted_at` IS NULL '); |
74 | 83 |
|
75 | 84 | foreach ($excels as $excel) {
|
76 | 85 | // 开启任务后 10 分钟未查询出结果=》失败
|
77 |
| - if ($excel['auto_delete'] > 0 && strtotime($excel['updated_at']) + 600 < time()) { |
78 |
| - ApiExcel::where('id', $excel['id'])->update(['state' => 5]); |
| 86 | + // if ($excel['auto_delete'] > 0 && strtotime($excel['updated_at']) + 600 < time()) { |
| 87 | + // ApiExcel::where('id', $excel['id'])->update(['state' => 5]); |
| 88 | + // } |
| 89 | + if (!$excel->sort_index || !$excel->created_at) { |
| 90 | + continue; |
| 91 | + } |
| 92 | + // 记录完成率 |
| 93 | + $finish = ($excel->total_excel / ($excel->sort_index + 1)) * 100; |
| 94 | + $finish = sprintf("%.2f", $finish); |
| 95 | + if (($finish > '96' && strtotime($excel->created_at) + 5 < time()) || ($finish > '50' && strtotime($excel->created_at) + 60 < time()) || ($finish > '10' && strtotime($excel->created_at) + 300 < time()) || ($finish > '1' && strtotime($excel->created_at) + 600 < time())) { |
| 96 | + ApiExcel::where('id', $excel->id)->update(['state' => 5]); |
79 | 97 | }
|
80 |
| - |
81 | 98 | }
|
82 | 99 | }
|
83 | 100 |
|
|
0 commit comments