Compare commits
127 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b76ef8e41 | |||
| 981a800053 | |||
| 79544f1ad1 | |||
| 93bd3d3f69 | |||
| 975f6f85a2 | |||
| 5a99181eaf | |||
| da5d74f519 | |||
| c878ed0ba4 | |||
| e7e24a1488 | |||
| 3dba884f64 | |||
| 4b30a59f6a | |||
| 704c0808ea | |||
| e738b084b4 | |||
| 77aa761e82 | |||
| 49ac53e751 | |||
| 2c0a431069 | |||
| 61893335ae | |||
| f87ddff585 | |||
| edcd873ff3 | |||
| 3ac7720f5b | |||
| a1fc45c3d7 | |||
| ac01000524 | |||
| 0a313e2b99 | |||
| 18b77760cd | |||
| 65a874c155 | |||
| 1bf851ff6b | |||
| 3309b101b6 | |||
| 27d8caec00 | |||
| 0cb14bd24b | |||
| 133455a041 | |||
| 9c5ba4b3e9 | |||
| 6db849de8d | |||
| 5506b3e725 | |||
| d1ccbbb5e0 | |||
| c8c95d9dc9 | |||
| 7d0ce48cd0 | |||
| c66b76d0be | |||
| febc53147e | |||
| c6279d6214 | |||
| 8deea95fb8 | |||
| 2512044bc5 | |||
| 3a1a124db3 | |||
| d2df0cbc1a | |||
| 15b6ac1b79 | |||
| 8fb60fcd76 | |||
| c8149e3754 | |||
| f49af928b6 | |||
| 63aadcb31f | |||
| 5f1fd4d93c | |||
| 84e8d26371 | |||
| 85fc29e76c | |||
| ad568fa3a7 | |||
| ea8d4d9611 | |||
| d3e74965f9 | |||
| 389c376c43 | |||
| 81eeaa64e4 | |||
| fbad6d9938 | |||
| 825539c792 | |||
| c73fe2d609 | |||
| ac66f768c3 | |||
| 84e2998139 | |||
| 19cab4f333 | |||
| 7d8c50aed8 | |||
| 8d98dc83be | |||
| 3adea33afe | |||
| 55250de396 | |||
| 5fffe53022 | |||
| 7a0ff2fbc5 | |||
| 4f539f4e78 | |||
| 9af827a11e | |||
| 3ddec68d7f | |||
| a5519b927b | |||
| 8add22f589 | |||
| 54f60e8765 | |||
| 6a60b03678 | |||
| 878e3b262b | |||
| a3ad2a6f17 | |||
| 79b32df2d5 | |||
| f40b79bb08 | |||
| ee380aa520 | |||
| dbf91656cb | |||
| 52845dfdb8 | |||
| 78c187e49f | |||
| fe105bd7d2 | |||
| 021e9ea23a | |||
| 794165fa67 | |||
| 6ef0f8b412 | |||
| fcb8630095 | |||
| ceafc139db | |||
| 283c7c2371 | |||
| 0b170cafb2 | |||
| d036f730ca | |||
| 55727bb219 | |||
| dc477978d3 | |||
| 7dda29a892 | |||
| 567cac606a | |||
| 49d435e4a5 | |||
| 5303c05274 | |||
| f6cb258259 | |||
| affb161ddf | |||
| a80f671a22 | |||
| 497cd95731 | |||
| 3ae85beb16 | |||
| 0a76e991b9 | |||
| bfc591b10a | |||
| b274140708 | |||
| a4a9a5618d | |||
| 0cf17a547e | |||
| 35ea526420 | |||
| 8ba04b4ccc | |||
| b83a0c4c96 | |||
| 21d3738125 | |||
| 2bd18b014d | |||
| 39be8f4b3b | |||
| 043b62688b | |||
| 38f5f57c4d | |||
| 2c7a755663 | |||
| 187b4311eb | |||
| 7d2c2cf7ff | |||
| 3771a8fb22 | |||
| 7561bacda5 | |||
| c7d6032010 | |||
| 48d9c5ce79 | |||
| b9d2288ac7 | |||
| 13877c6d58 | |||
| 320a01d822 | |||
| a435df8453 |
@@ -14,6 +14,7 @@ use Annotation\Annotation as SAnnotation;
|
||||
use Database\Connection;
|
||||
use Exception;
|
||||
use Http\Handler\Router;
|
||||
use Kiri\Events\OnBeforeCommandExecute;
|
||||
use Server\Server;
|
||||
use Kafka\KafkaProvider;
|
||||
use Kiri\Async;
|
||||
@@ -227,6 +228,8 @@ abstract class BaseApplication extends Component
|
||||
$eventProvider->on($key, $value, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (is_array($value)) {
|
||||
if (is_object($value[0]) && !($value[0] instanceof \Closure)) {
|
||||
$eventProvider->on($key, $value, 0);
|
||||
@@ -239,6 +242,7 @@ abstract class BaseApplication extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foreach ($value as $item) {
|
||||
if (!is_callable($item, true)) {
|
||||
throw new InitException("Class does not hav callback.");
|
||||
|
||||
@@ -22,7 +22,6 @@ use Kiri\Events\OnBeforeCommandExecute;
|
||||
use Kiri\Exception\NotFindClassException;
|
||||
use Kiri\FileListen\FileChangeCustomProcess;
|
||||
use ReflectionException;
|
||||
use Server\ServerCommand;
|
||||
use Server\ServerProviders;
|
||||
use stdClass;
|
||||
use Swoole\Process;
|
||||
@@ -30,6 +29,7 @@ use Swoole\Timer;
|
||||
use Symfony\Component\Console\Application as ConsoleApplication;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
/**
|
||||
@@ -192,12 +192,13 @@ class Application extends BaseApplication
|
||||
*/
|
||||
public function execute(array $argv): void
|
||||
{
|
||||
/** @var InputInterface $input */
|
||||
[$input, $output] = $this->argument($argv);
|
||||
try {
|
||||
$console = di(ConsoleApplication::class);
|
||||
$command = $input->getFirstArgument();
|
||||
if (empty($command)) {
|
||||
$command = 'list';
|
||||
$command = 'sw:server';
|
||||
}
|
||||
$command = $console->find($command);
|
||||
if ($command instanceof Command) {
|
||||
@@ -211,6 +212,7 @@ class Application extends BaseApplication
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $argv
|
||||
* @return array
|
||||
|
||||
@@ -13,73 +13,76 @@ class LocalService extends Component
|
||||
{
|
||||
|
||||
|
||||
private array $_components = [];
|
||||
private array $_components = [];
|
||||
|
||||
|
||||
private array $_definition = [];
|
||||
private array $_definition = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $define
|
||||
*/
|
||||
public function set($name, $define)
|
||||
{
|
||||
unset($this->_components[$name]);
|
||||
/**
|
||||
* @param $name
|
||||
* @param $define
|
||||
*/
|
||||
public function set($name, $define)
|
||||
{
|
||||
unset($this->_components[$name]);
|
||||
|
||||
$this->_definition[$name] = $define;
|
||||
}
|
||||
$this->_definition[$name] = $define;
|
||||
if (is_object($define) || $define instanceof \Closure) {
|
||||
$this->_components[$name] = $define;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get(string $name, $throwException = true)
|
||||
{
|
||||
if (isset($this->_components[$name])) {
|
||||
return $this->_components[$name];
|
||||
}
|
||||
if (isset($this->_definition[$name])) {
|
||||
$definition = $this->_definition[$name];
|
||||
if (is_object($definition) && !$definition instanceof \Closure) {
|
||||
return $this->_components[$name] = $definition;
|
||||
}
|
||||
return $this->_components[$name] = Kiri::createObject($definition);
|
||||
} else if ($throwException) {
|
||||
throw new \Exception("Unknown component ID: $name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get(string $name, $throwException = true)
|
||||
{
|
||||
if (isset($this->_components[$name])) {
|
||||
return $this->_components[$name];
|
||||
}
|
||||
if (isset($this->_definition[$name])) {
|
||||
$definition = $this->_definition[$name];
|
||||
if (is_object($definition) && !$definition instanceof \Closure) {
|
||||
return $this->_components[$name] = $definition;
|
||||
}
|
||||
return $this->_components[$name] = Kiri::createObject($definition);
|
||||
} else if ($throwException) {
|
||||
throw new \Exception("Unknown component ID: $name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $components
|
||||
*/
|
||||
public function setComponents(array $components)
|
||||
{
|
||||
foreach ($components as $name => $component) {
|
||||
$this->set($name, $component);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param array $components
|
||||
*/
|
||||
public function setComponents(array $components)
|
||||
{
|
||||
foreach ($components as $name => $component) {
|
||||
$this->set($name, $component);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public function has($id): bool
|
||||
{
|
||||
return isset($this->_components[$id]) || isset($this->_definition[$id]);
|
||||
}
|
||||
/**
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public function has($id): bool
|
||||
{
|
||||
return isset($this->_components[$id]) || isset($this->_definition[$id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*/
|
||||
public function remove($id): void
|
||||
{
|
||||
unset($this->_components[$id], $this->_definition[$id]);
|
||||
}
|
||||
/**
|
||||
* @param $id
|
||||
*/
|
||||
public function remove($id): void
|
||||
{
|
||||
unset($this->_components[$id], $this->_definition[$id]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -118,6 +118,8 @@ class ErrorHandler extends Component implements ErrorInterface
|
||||
{
|
||||
$path = ['file' => $file, 'line' => $line];
|
||||
|
||||
var_dump(func_get_args());
|
||||
|
||||
$data = Json::to($code, $this->category . ': ' . $message, $path);
|
||||
|
||||
write($data, $this->category);
|
||||
|
||||
@@ -8,9 +8,8 @@ use Kiri\Abstracts\Logger;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Coroutine\Barrier;
|
||||
use Swoole\Process;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
@@ -30,14 +29,19 @@ class FileChangeCustomProcess extends Command
|
||||
public int $int = -1;
|
||||
|
||||
|
||||
protected mixed $source = null;
|
||||
protected mixed $pipes = [];
|
||||
|
||||
protected ?Coroutine\Channel $channel = null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('sw:wather')
|
||||
->setDescription('server start')
|
||||
->addArgument('action', InputArgument::REQUIRED);
|
||||
->setDescription('server start');
|
||||
}
|
||||
|
||||
|
||||
@@ -46,37 +50,46 @@ class FileChangeCustomProcess extends Command
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
* @throws ConfigException
|
||||
* @throws \Swoole\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// TODO: Implement onHandler() method.
|
||||
set_error_handler([$this, 'onErrorHandler']);
|
||||
|
||||
$this->dirs = Config::get('inotify', [APP_PATH . 'app']);
|
||||
if (!extension_loaded('inotify')) {
|
||||
$driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]);
|
||||
} else {
|
||||
$driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
|
||||
}
|
||||
$make = Barrier::make();
|
||||
go(function () {
|
||||
$this->trigger_reload();
|
||||
});
|
||||
go(function () {
|
||||
$sign = Coroutine::waitSignal(SIGTERM, -1);
|
||||
if ($sign) {
|
||||
proc_open("php " . APP_PATH . "kiri.php sw:server stop", [], $pipes);
|
||||
}
|
||||
});
|
||||
go(function () use ($driver) {
|
||||
|
||||
if (Kiri::getPlatform()->isLinux()) {
|
||||
swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather');
|
||||
}
|
||||
$this->trigger_reload();
|
||||
Coroutine::create(function () use ($driver) {
|
||||
$driver->start();
|
||||
});
|
||||
Barrier::wait($make);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function stop(): void
|
||||
{
|
||||
if (is_resource($this->source)) {
|
||||
proc_terminate($this->source);
|
||||
while (proc_get_status($this->source)['running']) {
|
||||
Coroutine::sleep(1);
|
||||
}
|
||||
proc_close($this->source);
|
||||
$this->source = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @param $message
|
||||
@@ -95,12 +108,18 @@ class FileChangeCustomProcess extends Command
|
||||
|
||||
/**
|
||||
* 重启
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function trigger_reload()
|
||||
{
|
||||
Kiri::getDi()->get(Logger::class)->warning('change reload');
|
||||
|
||||
proc_open("php " . APP_PATH . "kiri.php sw:server restart", [], $pipes);
|
||||
$this->stop();
|
||||
Coroutine::create(function () {
|
||||
$this->source = proc_open("php " . APP_PATH . "kiri.php", [], $pipes);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ class Inotify
|
||||
|
||||
private array $watchFiles = [];
|
||||
|
||||
|
||||
protected int $cid;
|
||||
|
||||
const IG_DIR = [APP_PATH . 'commands', APP_PATH . '.git', APP_PATH . '.gitee'];
|
||||
|
||||
|
||||
@@ -41,6 +44,11 @@ class Inotify
|
||||
}
|
||||
|
||||
|
||||
public function clear()
|
||||
{
|
||||
Event::del($this->inotify);
|
||||
Event::exit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -117,12 +117,20 @@ class Scaner
|
||||
}
|
||||
|
||||
|
||||
private bool $isStop = false;
|
||||
|
||||
public function clear()
|
||||
{
|
||||
$this->isStop = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function tick()
|
||||
{
|
||||
if ($this->process->isReloading) {
|
||||
if ($this->process->isReloading || $this->isStop) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user