up. 添加worker的admin:worker
This commit is contained in:
parent
29d96ccba4
commit
de0f71f912
@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
namespace app\command\admin;
|
||||
|
||||
use app\entity\SysDevCrontab as CrontabModel;
|
||||
use app\enum\CrontabEnum;
|
||||
use Cron\CronExpression;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use Cron\CronExpression;
|
||||
use think\facade\Console;
|
||||
use app\entity\SysDevCrontab as CrontabModel;
|
||||
|
||||
/**
|
||||
* 定时任务
|
||||
@ -17,7 +17,7 @@ class Crontab extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('crontab')
|
||||
$this->setName('admin:crontab')
|
||||
->setDescription('定时任务');
|
||||
}
|
||||
|
||||
51
app/command/admin/Worker.php
Normal file
51
app/command/admin/Worker.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace app\command\admin;
|
||||
|
||||
|
||||
use app\http\worker\AdminWorker;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use Workerman\Worker as WmWorker;
|
||||
|
||||
class Worker extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('admin:worker')
|
||||
->addArgument('action', Argument::OPTIONAL, "start|stop|restart|reload|status|connections", 'start')
|
||||
->addOption('mode', 'm', Option::VALUE_OPTIONAL, 'Run the workerman server in daemon mode.')
|
||||
->setDescription('the workerman admin command');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('convert start');
|
||||
|
||||
$action = $input->getArgument('action');
|
||||
$mode = $input->getOption('mode');
|
||||
|
||||
|
||||
global $argv;
|
||||
|
||||
$argv = [];
|
||||
|
||||
array_unshift($argv, 'think', $action);
|
||||
if ($mode == 'd') {
|
||||
$argv[] = '-d';
|
||||
} else if ($mode == 'g') {
|
||||
$argv[] = '-g';
|
||||
}
|
||||
/*
|
||||
* 创建后台ws链接
|
||||
*/
|
||||
$adminWorker = new WmWorker('ws://0.0.0.0:19980');
|
||||
$adminWorker->onMessage = [AdminWorker::class, 'onMessage'];
|
||||
$adminWorker->onClose = [AdminWorker::class, 'onClose'];
|
||||
|
||||
WmWorker::runAll();
|
||||
}
|
||||
}
|
||||
15
app/http/worker/AdminWorker.php
Normal file
15
app/http/worker/AdminWorker.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace app\http\worker;
|
||||
|
||||
class AdminWorker
|
||||
{
|
||||
public function onMessage($connection,$data)
|
||||
{
|
||||
$connection->send(json_encode($data));
|
||||
}
|
||||
|
||||
public function onClose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@
|
||||
return [
|
||||
// 指令定义
|
||||
'commands' => [
|
||||
\app\command\Crontab::class,
|
||||
\app\command\admin\Crontab::class,
|
||||
\app\command\admin\Worker::class,
|
||||
],
|
||||
];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user