作者 刘锟

update

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class PullCode extends Command
{
protected $signature = 'pull_code';
protected $description = '自动拉取代码';
public function handle()
{
//查询更新代码任务
$is_pull = Redis::get('pull_code');
if (!$is_pull) {
return true;
}
try {
//拉取代码
$this->pullCode();
} catch (\Exception $e) {
Log::error('pull_code | error:' . $e->getMessage());
$this->output($e->getMessage());
}
Redis::set('pull_code', false);
return true;
}
/**
* 拉取代码
* @return bool
* @author Akun
* @date 2024/08/14 16:00
*/
public function pullCode()
{
$this->output('自动拉取代码: start.');
$shell = "cd /www/wwwroot/self_site && sudo git checkout . && sudo git pull 2>&1";
exec($shell, $out);
dump($out);
$this->output('自动拉取代码: end.');
return true;
}
/**
* 输出处理日志
* @param $message
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
}
}
... ...
... ... @@ -284,20 +284,30 @@ public function getRandInquiryText(Request $request)
}
/**
* 通知拉代码
* @author Akun
* @date 2025/06/13 15:18
*/
public function pullCode()
{
Redis::set('pull_code', true);
}
/**
* 拉代码
* @param Request $request
* @return string
*/
public function pullCode(Request $request)
{
$command = "cd /www/wwwroot/self_site && ./pull_custom_code.sh";
$resp = shell_exec($command);
if ($resp == null){
return $this->error("代码拉取失败");
}else{
return $this->success();
}
}
// public function pullCode(Request $request)
// {
// $command = "cd /www/wwwroot/self_site && ./pull_custom_code.sh";
// $resp = shell_exec($command);
// if ($resp == null){
// return $this->error("代码拉取失败");
// }else{
// return $this->success();
// }
// }
/**
* @param $url
... ...