合并分支 'master-server' 到 'master'
Master server 查看合并请求 !1082
正在显示
4 个修改的文件
包含
92 行增加
和
66 行删除
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :GeneratePage.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/2/10 17:00 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\Project; | ||
| 11 | + | ||
| 12 | +use App\Helper\Translate; | ||
| 13 | +use App\Models\Com\NoticeLog; | ||
| 14 | +use App\Models\Product\Keyword; | ||
| 15 | +use App\Models\RouteMap\RouteMap; | ||
| 16 | +use App\Services\ProjectServer; | ||
| 17 | +use Illuminate\Console\Command; | ||
| 18 | +use Illuminate\Support\Facades\DB; | ||
| 19 | +use Illuminate\Support\Facades\Redis; | ||
| 20 | + | ||
| 21 | +class GeneratePage extends Command | ||
| 22 | +{ | ||
| 23 | + /** | ||
| 24 | + * The name and signature of the console command. | ||
| 25 | + * | ||
| 26 | + * @var string | ||
| 27 | + */ | ||
| 28 | + protected $signature = 'generate_page'; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * The console command description. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $description = '批量导入关键字生成路由'; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * Create a new command instance. | ||
| 39 | + * | ||
| 40 | + * @return void | ||
| 41 | + */ | ||
| 42 | + public function __construct() | ||
| 43 | + { | ||
| 44 | + parent::__construct(); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * @return bool | ||
| 49 | + */ | ||
| 50 | + public function handle() | ||
| 51 | + { | ||
| 52 | + $noticeModel = new NoticeLog(); | ||
| 53 | + while (true){ | ||
| 54 | + $noticeInfo = $noticeModel->read(['status'=>0,'type'=>$noticeModel::GENERATE_PAGE]); | ||
| 55 | + if (empty($noticeInfo)) { | ||
| 56 | + sleep(10); | ||
| 57 | + continue; | ||
| 58 | + } | ||
| 59 | + try { | ||
| 60 | + $this->output(' taskID: ' . $noticeInfo['id'] . ' start'); | ||
| 61 | + $c_url = $noticeInfo['data']['c_url']; | ||
| 62 | + $c_params = $noticeInfo['data']['c_params']; | ||
| 63 | + $re = http_post($c_url, $c_params, [], true); | ||
| 64 | + if (isset($re['status']) && $re['status'] == 200) { | ||
| 65 | + $noticeModel->edit(['status'=>1],['id'=>$noticeInfo['id']]); | ||
| 66 | + $this->output($c_url . ' | 请求成功'); | ||
| 67 | + } else { | ||
| 68 | + $noticeModel->edit(['status'=>2],['id'=>$noticeInfo['id']]); | ||
| 69 | + $this->output($c_url . ' | ' . ($re['message'] ?? '未返回失败原因')); | ||
| 70 | + } | ||
| 71 | + $this->output(' taskID: ' . $noticeInfo['id'] . ' end'); | ||
| 72 | + } catch (\Exception $e) { | ||
| 73 | + $this->output(' taskID: ' . $noticeInfo['id'] . ', error: ' . $e->getMessage()); | ||
| 74 | + } | ||
| 75 | + sleep(2); | ||
| 76 | + } | ||
| 77 | + return true; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * 输出message | ||
| 83 | + * @param $message | ||
| 84 | + */ | ||
| 85 | + public function output($message) | ||
| 86 | + { | ||
| 87 | + echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL; | ||
| 88 | + } | ||
| 89 | +} |
| @@ -15,6 +15,7 @@ use App\Http\Controllers\Bside\BaseController; | @@ -15,6 +15,7 @@ use App\Http\Controllers\Bside\BaseController; | ||
| 15 | use App\Jobs\UpdatePageJob; | 15 | use App\Jobs\UpdatePageJob; |
| 16 | use App\Models\Blog\Blog; | 16 | use App\Models\Blog\Blog; |
| 17 | use App\Models\Blog\BlogCategory; | 17 | use App\Models\Blog\BlogCategory; |
| 18 | +use App\Models\Com\NoticeLog; | ||
| 18 | use App\Models\Com\Notify; | 19 | use App\Models\Com\Notify; |
| 19 | use App\Models\Com\UpdateLog; | 20 | use App\Models\Com\UpdateLog; |
| 20 | use App\Models\Com\UpdateNotify; | 21 | use App\Models\Com\UpdateNotify; |
| @@ -290,9 +291,7 @@ class CNoticeController extends BaseController | @@ -290,9 +291,7 @@ class CNoticeController extends BaseController | ||
| 290 | 'is_sitemap' => $is_sitemap | 291 | 'is_sitemap' => $is_sitemap |
| 291 | ]; | 292 | ]; |
| 292 | // http_post($c_url, json_encode($c_param)); | 293 | // http_post($c_url, json_encode($c_param)); |
| 293 | - | ||
| 294 | - //2024-10-11:改为异步请求 | ||
| 295 | - UpdatePageJob::dispatch(['c_url'=>$c_url,'c_params'=>json_encode($c_param)]); | 294 | + NoticeLog::createLog(NoticeLog::GENERATE_PAGE, json_encode(['c_url'=>$c_url,'c_params'=>$c_param])); |
| 296 | } | 295 | } |
| 297 | $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!'); | 296 | $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!'); |
| 298 | } | 297 | } |
app/Jobs/UpdatePageJob.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Jobs; | ||
| 4 | - | ||
| 5 | -use Illuminate\Bus\Queueable; | ||
| 6 | -use Illuminate\Contracts\Queue\ShouldQueue; | ||
| 7 | -use Illuminate\Foundation\Bus\Dispatchable; | ||
| 8 | -use Illuminate\Queue\InteractsWithQueue; | ||
| 9 | -use Illuminate\Queue\SerializesModels; | ||
| 10 | - | ||
| 11 | -class UpdatePageJob implements ShouldQueue | ||
| 12 | -{ | ||
| 13 | - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
| 14 | - | ||
| 15 | - public $tries = 3; // 可配置任务重试次数 | ||
| 16 | - | ||
| 17 | - protected $param; | ||
| 18 | - | ||
| 19 | - /** | ||
| 20 | - * Create a new job instance. | ||
| 21 | - * | ||
| 22 | - * @param $data | ||
| 23 | - * @return void | ||
| 24 | - */ | ||
| 25 | - public function __construct($data) | ||
| 26 | - { | ||
| 27 | - $this->param = $data; | ||
| 28 | - } | ||
| 29 | - | ||
| 30 | - /** | ||
| 31 | - * Execute the job. | ||
| 32 | - * B端更新页面异步请求 | ||
| 33 | - * @return bool | ||
| 34 | - */ | ||
| 35 | - public function handle() | ||
| 36 | - { | ||
| 37 | - $c_url = $this->param['c_url']; | ||
| 38 | - $c_params = $this->param['c_params']; | ||
| 39 | - | ||
| 40 | - try { | ||
| 41 | - $re = http_post($c_url, $c_params, [], true); | ||
| 42 | - if (isset($re['status']) && $re['status'] == 200) { | ||
| 43 | - $this->output($c_url . ' | 请求成功'); | ||
| 44 | - } else { | ||
| 45 | - $this->output($c_url . ' | ' . ($re['message'] ?? '未返回失败原因')); | ||
| 46 | - } | ||
| 47 | - } catch (\Exception $e) { | ||
| 48 | - $this->output($c_url . ' | 请求异常:' . $e->getMessage()); | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - return true; | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - /** | ||
| 56 | - * 输出处理日志 | ||
| 57 | - * @param $message | ||
| 58 | - */ | ||
| 59 | - public function output($message) | ||
| 60 | - { | ||
| 61 | - echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 62 | - } | ||
| 63 | -} |
| @@ -19,6 +19,7 @@ class NoticeLog extends Base | @@ -19,6 +19,7 @@ class NoticeLog extends Base | ||
| 19 | const DELETE_BLOG_CATEGORY = 'delete_blog_category'; | 19 | const DELETE_BLOG_CATEGORY = 'delete_blog_category'; |
| 20 | const DELETE_NEWS_CATEGORY = 'delete_news_category'; | 20 | const DELETE_NEWS_CATEGORY = 'delete_news_category'; |
| 21 | const DELETE_CUSTOM_CATEGORY = 'delete_custom_category'; | 21 | const DELETE_CUSTOM_CATEGORY = 'delete_custom_category'; |
| 22 | + const GENERATE_PAGE = 'generate_page';//生成页面单独改为守护进程 | ||
| 22 | const STATUS_PENDING = 0; | 23 | const STATUS_PENDING = 0; |
| 23 | const STATUS_SUCCESS = 1; | 24 | const STATUS_SUCCESS = 1; |
| 24 | const STATUS_FAIL = 2; | 25 | const STATUS_FAIL = 2; |
-
请 注册 或 登录 后发表评论