作者 lyh

gx

... ... @@ -10,6 +10,7 @@
namespace App\Console\Commands;
use App\Models\Mail\Mail;
use App\Models\Project\Project;
use App\Models\User\User;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
... ... @@ -40,17 +41,14 @@ class UpdateProgress extends Command
*/
public function handle()
{
$project_id = Redis::rpop('updateProgress');
while ($project_id){
echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;
try {
ProjectServer::useProject($project_id);
$this->getUpdateProgress($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;
//获取所有项目
$projectModel = new Project();
$list = $projectModel->list(['type'=>['in',[1,2,3,4]]]);
foreach ($list as $v){
echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->getUpdateProgress($v['id']);
DB::disconnect('custom_mysql');
}
}
... ... @@ -64,6 +62,7 @@ class UpdateProgress extends Command
public function getUpdateProgress($project_id){
$info = DB::connection('custom_mysql')->table('gl_update_progress')->whereRaw('total_num > current_num')->first();
if(!empty($info)){
//超时时间
$time = date("Y-m-d H:i:s",strtotime($info['created_at']) + $info['total_num'] * 60);
if($time > date("Y-m-d H:i:s")){
DB::connection('custom_mysql')->table('gl_update_progress')->where('id',$info['id'])->update(['current_num'=>$info['total_num']]);
... ... @@ -76,10 +75,9 @@ class UpdateProgress extends Command
$data["content"] = "部分页面更新超时,请重新更新,或联系管理员";
$mail = new Mail();
$mail->add($data);
}else{
Redis::lpush('updateProgress', $project_id);
}
}
echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
return true;
}
}
... ...
... ... @@ -141,7 +141,6 @@ class CNoticeController extends BaseController
];
$updateProgressModel = new UpdateProgress();
$updateProgressModel->insert($data);
Redis::lpush('updateProgress', $this->user['project_id']);
return true;
}
... ...