作者 刘锟

合并分支 'akun' 到 'master'

update



查看合并请求 !712
@@ -29,6 +29,7 @@ use App\Models\WebSetting\WebSettingReceiving; @@ -29,6 +29,7 @@ use App\Models\WebSetting\WebSettingReceiving;
29 use App\Services\CosService; 29 use App\Services\CosService;
30 use App\Services\ProjectServer; 30 use App\Services\ProjectServer;
31 use Illuminate\Console\Command; 31 use Illuminate\Console\Command;
  32 +use Illuminate\Support\Facades\Cache;
32 use Illuminate\Support\Facades\DB; 33 use Illuminate\Support\Facades\DB;
33 use Illuminate\Support\Facades\Redis; 34 use Illuminate\Support\Facades\Redis;
34 35
@@ -67,9 +68,14 @@ class ProjectUpdate extends Command @@ -67,9 +68,14 @@ class ProjectUpdate extends Command
67 protected function start_update() 68 protected function start_update()
68 { 69 {
69 $task_id = $this->get_task(); 70 $task_id = $this->get_task();
70 - if (!$task_id) { 71 + if ($task_id === false) {
  72 + //所有任务执行完成
71 sleep(60); 73 sleep(60);
72 return true; 74 return true;
  75 + } elseif ($task_id === 0) {
  76 + //队列任务已处理完,有进程正在查询数据库,等待5秒后执行
  77 + sleep(5);
  78 + return true;
73 } 79 }
74 80
75 $task = UpdateLog::where('id', $task_id)->where('status', UpdateLog::STATUS_UN)->first(); 81 $task = UpdateLog::where('id', $task_id)->where('status', UpdateLog::STATUS_UN)->first();
@@ -794,6 +800,11 @@ class ProjectUpdate extends Command @@ -794,6 +800,11 @@ class ProjectUpdate extends Command
794 return $task_id; 800 return $task_id;
795 } 801 }
796 802
  803 + if (!Cache::add('console_update_task_select_mysql', true, 5)) {
  804 + //如果存在数据锁,表示有其他进程已往下执行,当前进程直接返回
  805 + return 0;
  806 + }
  807 +
797 $task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('sort', 'asc')->orderBy('updated_at', 'asc')->limit(20)->get(); 808 $task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('sort', 'asc')->orderBy('updated_at', 'asc')->limit(20)->get();
798 if ($task_list->count() == 0) { 809 if ($task_list->count() == 0) {
799 return false; 810 return false;