UpdateProgress.php
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* @remark :
* @name :UpdateProgress.php
* @author :lyh
* @method :post
* @time :2023/11/1 9:22
*/
namespace App\Console\Commands;
use App\Models\Mail\Mail;
use App\Models\User\User;
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()
{
$project_id = Redis::rpop('updateProgress');
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;
}
/**
* @remark :查看是否有为更新的记录
* @name :updateProgress
* @author :lyh
* @method :post
* @time :2023/11/1 10:47
*/
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']]);
//获取当前项目的用户
$user = new User();
$info = $user->read(['project_id'=>$project_id,'role'=>0]);
//发送站内信,请重新更新
$data["title"] = "页面更新通知";
$data["user_list"] = $info['id'];
$data["content"] = "部分页面更新超时,请重新更新,或联系管理员";
$mail = new Mail();
$mail->add($data);
}else{
Redis::lpush('updateProgress', $project_id);
}
}
return true;
}
}