作者 刘锟

update

@@ -16,6 +16,7 @@ use App\Models\Template\BCustomTemplate; @@ -16,6 +16,7 @@ use App\Models\Template\BCustomTemplate;
16 use App\Services\CosService; 16 use App\Services\CosService;
17 use App\Services\ProjectServer; 17 use App\Services\ProjectServer;
18 use Illuminate\Console\Command; 18 use Illuminate\Console\Command;
  19 +use Illuminate\Support\Facades\Cache;
19 use Illuminate\Support\Facades\DB; 20 use Illuminate\Support\Facades\DB;
20 use Illuminate\Support\Facades\Redis; 21 use Illuminate\Support\Facades\Redis;
21 22
@@ -54,10 +55,14 @@ class HtmlCollect extends Command @@ -54,10 +55,14 @@ class HtmlCollect extends Command
54 protected function start_collect() 55 protected function start_collect()
55 { 56 {
56 $task_id = $this->get_task(); 57 $task_id = $this->get_task();
57 - if (!$task_id) { 58 + if ($task_id === false) {
58 //所有项目采集完成 59 //所有项目采集完成
59 sleep(60); 60 sleep(60);
60 return true; 61 return true;
  62 + } elseif ($task_id === 0) {
  63 + //队列任务已处理完,有进程正在查询数据库,等待2秒后执行
  64 + sleep(2);
  65 + return true;
61 } 66 }
62 67
63 $task_arr = explode('_', $task_id); 68 $task_arr = explode('_', $task_id);
@@ -142,6 +147,11 @@ class HtmlCollect extends Command @@ -142,6 +147,11 @@ class HtmlCollect extends Command
142 return $task_id; 147 return $task_id;
143 } 148 }
144 149
  150 + if (!Cache::add('html_collect_select_mysql', true, 10)) {
  151 + // 如果存在数据锁,则表示有其他进程正在查询数据库,直接返回
  152 + return 0;
  153 + }
  154 +
145 $update_log_list = UpdateLog::where('status', UpdateLog::STATUS_COM)->where('collect_status', UpdateLog::COLLECT_STATUS_UN)->orderBy('updated_at', 'asc')->limit(20)->get(); 155 $update_log_list = UpdateLog::where('status', UpdateLog::STATUS_COM)->where('collect_status', UpdateLog::COLLECT_STATUS_UN)->orderBy('updated_at', 'asc')->limit(20)->get();
146 if ($update_log_list->count() == 0) { 156 if ($update_log_list->count() == 0) {
147 return false; 157 return false;