Skip to content

Commit 2f299fa

Browse files
committed
update 失败任务:1. logs 10s 一直无新增数据;2. 查询最新更新时间大于 20 秒未新增数据--失败
1 parent c770917 commit 2f299fa

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

laravel/app/Http/Repository/ApiRepository.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,28 @@ public function autoFailed()
7979
// 3. 完成率 10% -- 5 分钟不再增加
8080
// 4. 完成率 1% -- 10 分钟不再增加
8181
// 5. 完成率 0% -- 30 分钟不再增加
82-
$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 id FROM boss_api_excel_logs WHERE boss_api_excel_logs.api_excel_id=ae.id ORDER BY sort_index DESC LIMIT 1) WHERE ae.state=1 AND ae.`deleted_at` IS NULL ');
82+
// $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 id FROM boss_api_excel_logs WHERE boss_api_excel_logs.api_excel_id=ae.id ORDER BY sort_index DESC LIMIT 1) WHERE ae.state=1 AND ae.`deleted_at` IS NULL ');
83+
$excels = DB::connection()->select('SELECT ae.id,ae.api_param_id,ae.state,ae.total_excel,ael.api_excel_id,ael.sort_index,ae.updated_at,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 id FROM boss_api_excel_logs WHERE boss_api_excel_logs.api_excel_id=ae.id ORDER BY id DESC LIMIT 1) WHERE ae.state=1 AND ae.`deleted_at` IS NULL ');
8384

8485
foreach ($excels as $excel) {
8586
// 开启任务后 10 分钟未查询出结果=》失败
8687
// if ($excel['auto_delete'] > 0 && strtotime($excel['updated_at']) + 600 < time()) {
8788
// ApiExcel::where('id', $excel['id'])->update(['state' => 5]);
8889
// }
89-
if (!$excel->sort_index || !$excel->created_at) {
90-
continue;
91-
}
92-
// 记录完成率
93-
$finish = (($excel->sort_index + 1) / $excel->total_excel) * 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()) || ($finish >= 0 && strtotime($excel->created_at) + 1800 < time())) {
90+
// if (!$excel->sort_index || !$excel->created_at) {
91+
// continue;
92+
// }
93+
94+
// 1. logs 10s 一直无新增数据;2. 查询最新更新时间大于 20 秒未新增数据--失败
95+
if ((!$excel->sort_index && $excel['updated_at'] + 10 < time()) || strtotime($excel->created_at) + 20 < time()) {
9696
ApiExcel::where('id', $excel->id)->update(['state' => 5]);
9797
}
98+
// 记录完成率
99+
// $finish = (($excel->sort_index + 1) / $excel->total_excel) * 100;
100+
// $finish = sprintf("%.2f", $finish);
101+
// 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()) || ($finish >= 0 && strtotime($excel->created_at) + 1800 < time())) {
102+
// ApiExcel::where('id', $excel->id)->update(['state' => 5]);
103+
// }
98104
}
99105
}
100106

0 commit comments

Comments
 (0)