新增调度命令
This commit is contained in:
parent
da683a3592
commit
f15eedfa9c
93
extend/catcher/command/CatchScheduleCommand.php
Normal file
93
extend/catcher/command/CatchScheduleCommand.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace catcher\command;
|
||||
|
||||
use catcher\library\crontab\ManageProcess;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
|
||||
class CatchScheduleCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('catch:schedule')
|
||||
->addArgument('option', Argument::OPTIONAL, '[start|reload|stop|restart||status]', 'start')
|
||||
->setDescription('start task schedule');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$process = new ManageProcess();
|
||||
$option = $input->getArgument('option');
|
||||
$this->{$option}($process);
|
||||
}
|
||||
|
||||
/**
|
||||
* 进程启动
|
||||
*
|
||||
* @time 2020年07月07日
|
||||
* @param ManageProcess $process
|
||||
* @return void
|
||||
*/
|
||||
protected function start(ManageProcess $process)
|
||||
{
|
||||
$process->start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态输出
|
||||
*
|
||||
* @time 2020年07月07日
|
||||
* @param ManageProcess $process
|
||||
* @return void
|
||||
*/
|
||||
protected function status(ManageProcess $process)
|
||||
{
|
||||
$process->status();
|
||||
|
||||
$this->output->info($process->output());
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止任务
|
||||
*
|
||||
* @time 2020年07月07日
|
||||
* @param ManageProcess $process
|
||||
* @return void
|
||||
*/
|
||||
protected function stop(ManageProcess $process)
|
||||
{
|
||||
$process->stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启任务
|
||||
*
|
||||
* @time 2020年07月07日
|
||||
* @param ManageProcess $process
|
||||
* @return void
|
||||
*/
|
||||
protected function reload(ManageProcess $process)
|
||||
{
|
||||
$process->reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启
|
||||
*
|
||||
* @time 2020年07月07日
|
||||
* @param ManageProcess $process
|
||||
* @return void
|
||||
*/
|
||||
protected function restart(ManageProcess $process)
|
||||
{
|
||||
$process->stop();
|
||||
|
||||
$process->start();
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
<?php
|
@ -1,103 +0,0 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace catcher\command\worker;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use think\Config;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use Workerman\Worker;
|
||||
|
||||
class WsWorkerCommand extends Command
|
||||
{
|
||||
protected $address = '127.0.0.1:10001';
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('ws:server')
|
||||
->addArgument('option', Argument::OPTIONAL, '[start|reload|stop|restart|reload|status|connections]', 'start')
|
||||
->addOption('mode', '-m', Option::VALUE_REQUIRED, 'worker start mode')
|
||||
->addOption('number', '-n', Option::VALUE_REQUIRED, 'worker number')
|
||||
->addOption('address', '-a',Option::VALUE_REQUIRED, 'listen address, like \'127.0.0.1:9090\'')
|
||||
->setDescription('start websocket server, default listen 127.0.0.1 port 10001');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$this->setWokrermanCommnd();
|
||||
|
||||
$this->start();
|
||||
}
|
||||
|
||||
/**
|
||||
* worker start
|
||||
*
|
||||
* @author JaguarJack
|
||||
* @email njphper@gmail.com
|
||||
* @time 2020/1/23
|
||||
* @return void
|
||||
*/
|
||||
protected function start()
|
||||
{
|
||||
$ws = new Worker(sprintf('websocket://%s', $this->getAddress()));
|
||||
|
||||
$ws->count = $this->getWorkerNumber();
|
||||
|
||||
$ws->runAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author JaguarJack
|
||||
* @email njphper@gmail.com
|
||||
* @time 2020/1/23
|
||||
*/
|
||||
protected function getAddress()
|
||||
{
|
||||
return $this->input->getOption('address') ? : $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* worker number
|
||||
*
|
||||
* @author JaguarJack
|
||||
* @email njphper@gmail.com
|
||||
* @time 2020/1/23
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getWorkerNumber()
|
||||
{
|
||||
return $this->input->getOption('number') ? : 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* set workerman command
|
||||
*
|
||||
* @author JaguarJack
|
||||
* @email njphper@gmail.com
|
||||
* @time 2020/1/23
|
||||
* @return void
|
||||
*/
|
||||
protected function setWokrermanCommnd()
|
||||
{
|
||||
global $argv;
|
||||
|
||||
$option = $this->input->getArgument('option');
|
||||
|
||||
$mode = $this->input->getOption('mode');
|
||||
|
||||
if ($option) {
|
||||
array_unshift($argv, $mode);
|
||||
}
|
||||
|
||||
array_unshift($argv, $option);
|
||||
|
||||
array_unshift($argv, 'catchWorker');
|
||||
}
|
||||
}
|
10
extend/catcher/library/crontab/Process.php
Normal file
10
extend/catcher/library/crontab/Process.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
10
extend/catcher/library/crontab/RegisterSignal.php
Normal file
10
extend/catcher/library/crontab/RegisterSignal.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
10
extend/catcher/library/crontab/Store.php
Normal file
10
extend/catcher/library/crontab/Store.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
Loading…
x
Reference in New Issue
Block a user