UpdateProgress.php 1.8 KB
<?php
/**
 * @remark :
 * @name   :UpdateProgress.php
 * @author :lyh
 * @method :post
 * @time   :2023/11/1 9:22
 */

namespace App\Console\Commands;

use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Models\Com\UpdateProgress as UpdateProgressModel;

class UpdateProgress extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'update_progress';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '守护进程--更新界面';
    /**
     * @name   :(定时执行)handle
     * @author :lyh
     * @method :post
     * @time   :2023/5/12 14:48
     */
    public function handle()
    {
        while (true){
            $project_id = Redis::rpop('updateSeoTdk');
            if(!$project_id){
                sleep(2);
                continue;
            }
            echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;

            try {
                ProjectServer::useProject($project_id);
                DB::disconnect('custom_mysql');
            }catch (\Exception $e){
                echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
            }
            echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
        }
    }

    /**
     * @remark :查看是否有为更新的记录
     * @name   :updateProgress
     * @author :lyh
     * @method :post
     * @time   :2023/11/1 10:47
     */
    public function getUpdateProgress(){
        $list = DB::connection('custom_mysql')->table('gl_update_progress')->whereRaw('total_num > current_num')->get();
        if(!empty($list)){
            $list = $list->toArray();
        }
    }
}