作者 lyh

gx

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :UpdateProgress.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2023/11/1 9:22
  8 + */
  9 +
  10 +namespace App\Console\Commands;
  11 +
  12 +use App\Services\ProjectServer;
  13 +use Illuminate\Console\Command;
  14 +use Illuminate\Support\Facades\DB;
  15 +use Illuminate\Support\Facades\Redis;
  16 +use App\Models\Com\UpdateProgress as UpdateProgressModel;
  17 +
  18 +class UpdateProgress extends Command
  19 +{
  20 + /**
  21 + * The name and signature of the console command.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $signature = 'update_progress';
  26 +
  27 + /**
  28 + * The console command description.
  29 + *
  30 + * @var string
  31 + */
  32 + protected $description = '守护进程--更新界面';
  33 + /**
  34 + * @name :(定时执行)handle
  35 + * @author :lyh
  36 + * @method :post
  37 + * @time :2023/5/12 14:48
  38 + */
  39 + public function handle()
  40 + {
  41 + while (true){
  42 + $project_id = Redis::rpop('updateSeoTdk');
  43 + if(!$project_id){
  44 + sleep(2);
  45 + continue;
  46 + }
  47 + echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;
  48 +
  49 + try {
  50 + ProjectServer::useProject($project_id);
  51 + DB::disconnect('custom_mysql');
  52 + }catch (\Exception $e){
  53 + echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
  54 + }
  55 + echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
  56 + }
  57 + }
  58 +
  59 + /**
  60 + * @remark :查看是否有为更新的记录
  61 + * @name :updateProgress
  62 + * @author :lyh
  63 + * @method :post
  64 + * @time :2023/11/1 10:47
  65 + */
  66 + public function getUpdateProgress(){
  67 + $list = DB::connection('custom_mysql')->table('gl_update_progress')->whereRaw('total_num > current_num')->get();
  68 + if(!empty($list)){
  69 + $list = $list->toArray();
  70 + }
  71 + }
  72 +}
@@ -3,10 +3,7 @@ @@ -3,10 +3,7 @@
3 namespace App\Console\Commands; 3 namespace App\Console\Commands;
4 4
5 use App\Helper\Common; 5 use App\Helper\Common;
6 -use App\Helper\Translate;  
7 -use App\Models\Ai\AiCommand as AiCommandModel;  
8 use App\Models\Project\DeployOptimize; 6 use App\Models\Project\DeployOptimize;
9 -use App\Models\Project\Project;  
10 use App\Services\ProjectServer; 7 use App\Services\ProjectServer;
11 use Illuminate\Console\Command; 8 use Illuminate\Console\Command;
12 use Illuminate\Support\Facades\DB; 9 use Illuminate\Support\Facades\DB;
@@ -19,6 +19,7 @@ use App\Models\Project\Project; @@ -19,6 +19,7 @@ use App\Models\Project\Project;
19 use App\Models\RouteMap\RouteMap; 19 use App\Models\RouteMap\RouteMap;
20 use App\Models\WebSetting\WebSettingCountry; 20 use App\Models\WebSetting\WebSettingCountry;
21 use Illuminate\Http\Request; 21 use Illuminate\Http\Request;
  22 +use Illuminate\Support\Facades\Redis;
22 23
23 /** 24 /**
24 * @remark :通知C端 25 * @remark :通知C端
@@ -139,7 +140,9 @@ class CNoticeController extends BaseController @@ -139,7 +140,9 @@ class CNoticeController extends BaseController
139 'created_at'=>date('Y-m-d H;i:s') 140 'created_at'=>date('Y-m-d H;i:s')
140 ]; 141 ];
141 $updateProgressModel = new UpdateProgress(); 142 $updateProgressModel = new UpdateProgress();
142 - return $updateProgressModel->insert($data); 143 + $updateProgressModel->insert($data);
  144 + Redis::lpush('updateProgress', $this->param['project_id']);
  145 + return true;
143 } 146 }
144 147
145 /** 148 /**