diff --git a/app/admin/controller/Queue.php b/app/admin/controller/Queue.php index 5ee008beb..26cb33e35 100644 --- a/app/admin/controller/Queue.php +++ b/app/admin/controller/Queue.php @@ -45,19 +45,13 @@ class Queue extends Controller */ public function index() { - // 检查进程状态 - if (AdminService::instance()->isSuper()) try { - $this->process = ProcessService::instance(); - if ($this->process->iswin() || empty($_SERVER['USER'])) { - $this->command = $this->process->think('xadmin:queue start'); + if (AdminService::instance()->isSuper()) { + $process = ProcessService::instance(); + if ($process->iswin() || empty($_SERVER['USER'])) { + $this->command = $process->think('xadmin:queue start'); } else { - $this->command = "sudo -u {$_SERVER['USER']} {$this->process->think('xadmin:queue start')}"; + $this->command = "sudo -u {$_SERVER['USER']} {$process->think('xadmin:queue start')}"; } - $this->message = $this->app->console->call('xadmin:queue', ['status'])->fetch(); - $this->listen = preg_match('/process.*?\d+.*?running/', $this->message, $attr); - } catch (\Exception $exception) { - $this->listen = false; - $this->message = $exception->getMessage(); } // 任务状态统计 $this->total = ['dos' => 0, 'pre' => 0, 'oks' => 0, 'ers' => 0]; diff --git a/app/admin/controller/api/Plugs.php b/app/admin/controller/api/Plugs.php index 2341f1147..ffd9b4925 100644 --- a/app/admin/controller/api/Plugs.php +++ b/app/admin/controller/api/Plugs.php @@ -17,6 +17,7 @@ namespace app\admin\controller\api; use think\admin\Controller; use think\admin\service\AdminService; +use think\admin\service\ProcessService; use think\admin\service\SystemService; use think\exception\HttpResponseException; @@ -99,6 +100,26 @@ class Plugs extends Controller } } + /** + * 检查任务状态 + * @login true + */ + public function queue() + { + if (AdminService::instance()->isSuper()) try { + $message = $this->app->console->call('xadmin:queue', ['status'])->fetch(); + if (preg_match('/process.*?\d+.*?running/', $message, $attrs)) { + echo '' . $message . ''; + } else { + echo '' . $message . ''; + } + } catch (\Exception $exception) { + echo '' . $exception->getMessage() . ''; + } else { + $this->error('只有超级管理员才能操作!'); + } + } + /** * 优化数据库 * @login true diff --git a/app/admin/view/queue/index_search.html b/app/admin/view/queue/index_search.html index 00869e177..2efa47020 100644 --- a/app/admin/view/queue/index_search.html +++ b/app/admin/view/queue/index_search.html @@ -3,14 +3,11 @@
{$command|default='--'}