正在显示
2 个修改的文件
包含
82 行增加
和
10 行删除
app/Console/Commands/PullCode.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands; | ||
| 4 | + | ||
| 5 | +use Illuminate\Console\Command; | ||
| 6 | +use Illuminate\Support\Facades\Log; | ||
| 7 | +use Illuminate\Support\Facades\Redis; | ||
| 8 | + | ||
| 9 | +class PullCode extends Command | ||
| 10 | +{ | ||
| 11 | + protected $signature = 'pull_code'; | ||
| 12 | + protected $description = '自动拉取代码'; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + public function handle() | ||
| 16 | + { | ||
| 17 | + //查询更新代码任务 | ||
| 18 | + $is_pull = Redis::get('pull_code'); | ||
| 19 | + if (!$is_pull) { | ||
| 20 | + return true; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + try { | ||
| 24 | + //拉取代码 | ||
| 25 | + $this->pullCode(); | ||
| 26 | + } catch (\Exception $e) { | ||
| 27 | + Log::error('pull_code | error:' . $e->getMessage()); | ||
| 28 | + $this->output($e->getMessage()); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + Redis::set('pull_code', false); | ||
| 32 | + return true; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 拉取代码 | ||
| 37 | + * @return bool | ||
| 38 | + * @author Akun | ||
| 39 | + * @date 2024/08/14 16:00 | ||
| 40 | + */ | ||
| 41 | + public function pullCode() | ||
| 42 | + { | ||
| 43 | + $this->output('自动拉取代码: start.'); | ||
| 44 | + | ||
| 45 | + $shell = "cd /www/wwwroot/self_site && sudo git checkout . && sudo git pull 2>&1"; | ||
| 46 | + exec($shell, $out); | ||
| 47 | + dump($out); | ||
| 48 | + | ||
| 49 | + $this->output('自动拉取代码: end.'); | ||
| 50 | + | ||
| 51 | + return true; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 输出处理日志 | ||
| 56 | + * @param $message | ||
| 57 | + */ | ||
| 58 | + public function output($message) | ||
| 59 | + { | ||
| 60 | + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 61 | + } | ||
| 62 | +} | 
| @@ -284,20 +284,30 @@ public function getRandInquiryText(Request $request) | @@ -284,20 +284,30 @@ public function getRandInquiryText(Request $request) | ||
| 284 | } | 284 | } | 
| 285 | 285 | ||
| 286 | /** | 286 | /** | 
| 287 | + * 通知拉代码 | ||
| 288 | + * @author Akun | ||
| 289 | + * @date 2025/06/13 15:18 | ||
| 290 | + */ | ||
| 291 | + public function pullCode() | ||
| 292 | + { | ||
| 293 | + Redis::set('pull_code', true); | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + /** | ||
| 287 | * 拉代码 | 297 | * 拉代码 | 
| 288 | * @param Request $request | 298 | * @param Request $request | 
| 289 | * @return string | 299 | * @return string | 
| 290 | */ | 300 | */ | 
| 291 | - public function pullCode(Request $request) | ||
| 292 | - { | ||
| 293 | - $command = "cd /www/wwwroot/self_site && ./pull_custom_code.sh"; | ||
| 294 | - $resp = shell_exec($command); | ||
| 295 | - if ($resp == null){ | ||
| 296 | - return $this->error("代码拉取失败"); | ||
| 297 | - }else{ | ||
| 298 | - return $this->success(); | ||
| 299 | - } | ||
| 300 | - } | 301 | +// public function pullCode(Request $request) | 
| 302 | +// { | ||
| 303 | +// $command = "cd /www/wwwroot/self_site && ./pull_custom_code.sh"; | ||
| 304 | +// $resp = shell_exec($command); | ||
| 305 | +// if ($resp == null){ | ||
| 306 | +// return $this->error("代码拉取失败"); | ||
| 307 | +// }else{ | ||
| 308 | +// return $this->success(); | ||
| 309 | +// } | ||
| 310 | +// } | ||
| 301 | 311 | ||
| 302 | /** | 312 | /** | 
| 303 | * @param $url | 313 | * @param $url | 
- 
请 注册 或 登录 后发表评论