Compare commits

..

127 Commits

Author SHA1 Message Date
as2252258 8b76ef8e41 改名 2021-11-05 14:45:24 +08:00
as2252258 981a800053 改名 2021-11-05 14:44:10 +08:00
as2252258 79544f1ad1 改名 2021-11-05 14:38:11 +08:00
as2252258 93bd3d3f69 改名 2021-11-05 14:35:16 +08:00
as2252258 975f6f85a2 改名 2021-11-05 14:27:13 +08:00
as2252258 5a99181eaf 改名 2021-11-05 14:25:32 +08:00
as2252258 da5d74f519 改名 2021-11-05 14:24:49 +08:00
as2252258 c878ed0ba4 改名 2021-11-05 14:22:57 +08:00
as2252258 e7e24a1488 改名 2021-11-05 11:30:32 +08:00
as2252258 3dba884f64 改名 2021-11-05 11:07:06 +08:00
as2252258 4b30a59f6a 改名 2021-11-05 11:04:45 +08:00
as2252258 704c0808ea 改名 2021-11-05 11:04:24 +08:00
as2252258 e738b084b4 改名 2021-11-05 11:03:00 +08:00
as2252258 77aa761e82 改名 2021-11-05 11:01:42 +08:00
as2252258 49ac53e751 改名 2021-11-05 10:58:34 +08:00
as2252258 2c0a431069 111 2021-11-05 01:24:08 +08:00
as2252258 61893335ae 111 2021-11-05 01:23:41 +08:00
as2252258 f87ddff585 111 2021-11-05 01:23:22 +08:00
as2252258 edcd873ff3 111 2021-11-05 01:22:16 +08:00
as2252258 3ac7720f5b 111 2021-11-05 01:21:47 +08:00
as2252258 a1fc45c3d7 111 2021-11-05 01:19:31 +08:00
as2252258 ac01000524 111 2021-11-05 01:16:22 +08:00
as2252258 0a313e2b99 111 2021-11-05 01:14:47 +08:00
as2252258 18b77760cd 111 2021-11-05 01:14:27 +08:00
as2252258 65a874c155 111 2021-11-05 01:14:01 +08:00
as2252258 1bf851ff6b 111 2021-11-05 01:13:02 +08:00
as2252258 3309b101b6 111 2021-11-05 01:12:45 +08:00
as2252258 27d8caec00 111 2021-11-05 01:12:36 +08:00
as2252258 0cb14bd24b 111 2021-11-05 01:11:50 +08:00
as2252258 133455a041 111 2021-11-05 01:11:32 +08:00
as2252258 9c5ba4b3e9 111 2021-11-05 01:10:58 +08:00
as2252258 6db849de8d 111 2021-11-05 01:10:42 +08:00
as2252258 5506b3e725 111 2021-11-05 01:09:59 +08:00
as2252258 d1ccbbb5e0 111 2021-11-05 01:09:20 +08:00
as2252258 c8c95d9dc9 111 2021-11-05 01:08:40 +08:00
as2252258 7d0ce48cd0 111 2021-11-05 01:07:43 +08:00
as2252258 c66b76d0be 111 2021-11-05 01:07:23 +08:00
as2252258 febc53147e 111 2021-11-05 01:05:26 +08:00
as2252258 c6279d6214 111 2021-11-05 01:05:01 +08:00
as2252258 8deea95fb8 111 2021-11-05 01:01:13 +08:00
as2252258 2512044bc5 111 2021-11-05 00:59:38 +08:00
as2252258 3a1a124db3 111 2021-11-05 00:58:03 +08:00
as2252258 d2df0cbc1a 111 2021-11-05 00:57:34 +08:00
as2252258 15b6ac1b79 111 2021-11-05 00:55:20 +08:00
as2252258 8fb60fcd76 111 2021-11-05 00:54:37 +08:00
as2252258 c8149e3754 111 2021-11-05 00:41:25 +08:00
as2252258 f49af928b6 111 2021-11-05 00:40:53 +08:00
as2252258 63aadcb31f 111 2021-11-05 00:39:53 +08:00
as2252258 5f1fd4d93c 111 2021-11-05 00:38:51 +08:00
as2252258 84e8d26371 111 2021-11-05 00:38:26 +08:00
as2252258 85fc29e76c 111 2021-11-05 00:36:55 +08:00
as2252258 ad568fa3a7 111 2021-11-05 00:36:34 +08:00
as2252258 ea8d4d9611 111 2021-11-05 00:34:12 +08:00
as2252258 d3e74965f9 111 2021-11-05 00:33:15 +08:00
as2252258 389c376c43 111 2021-11-05 00:32:52 +08:00
as2252258 81eeaa64e4 111 2021-11-05 00:25:47 +08:00
as2252258 fbad6d9938 111 2021-11-05 00:24:08 +08:00
as2252258 825539c792 111 2021-11-05 00:23:31 +08:00
as2252258 c73fe2d609 111 2021-11-05 00:21:42 +08:00
as2252258 ac66f768c3 111 2021-11-05 00:20:30 +08:00
as2252258 84e2998139 111 2021-11-05 00:14:54 +08:00
as2252258 19cab4f333 111 2021-11-05 00:13:52 +08:00
as2252258 7d8c50aed8 111 2021-11-05 00:12:13 +08:00
as2252258 8d98dc83be 111 2021-11-05 00:08:43 +08:00
as2252258 3adea33afe 111 2021-11-05 00:06:41 +08:00
as2252258 55250de396 111 2021-11-05 00:03:16 +08:00
as2252258 5fffe53022 111 2021-11-05 00:02:43 +08:00
as2252258 7a0ff2fbc5 111 2021-11-04 23:52:12 +08:00
as2252258 4f539f4e78 111 2021-11-04 23:50:26 +08:00
as2252258 9af827a11e 111 2021-11-04 23:49:35 +08:00
as2252258 3ddec68d7f 111 2021-11-04 23:48:53 +08:00
as2252258 a5519b927b 111 2021-11-04 23:46:44 +08:00
as2252258 8add22f589 111 2021-11-04 23:44:47 +08:00
as2252258 54f60e8765 111 2021-11-04 23:41:15 +08:00
as2252258 6a60b03678 111 2021-11-04 23:39:40 +08:00
as2252258 878e3b262b 111 2021-11-04 23:12:57 +08:00
as2252258 a3ad2a6f17 改名 2021-11-04 19:01:09 +08:00
as2252258 79b32df2d5 改名 2021-11-04 19:00:53 +08:00
as2252258 f40b79bb08 改名 2021-11-04 18:58:10 +08:00
as2252258 ee380aa520 改名 2021-11-04 18:57:49 +08:00
as2252258 dbf91656cb 改名 2021-11-04 18:57:13 +08:00
as2252258 52845dfdb8 改名 2021-11-04 18:56:54 +08:00
as2252258 78c187e49f 改名 2021-11-04 18:53:58 +08:00
as2252258 fe105bd7d2 改名 2021-11-04 18:53:31 +08:00
as2252258 021e9ea23a 改名 2021-11-04 18:47:32 +08:00
as2252258 794165fa67 改名 2021-11-04 18:47:23 +08:00
as2252258 6ef0f8b412 改名 2021-11-04 18:46:57 +08:00
as2252258 fcb8630095 改名 2021-11-04 18:43:19 +08:00
as2252258 ceafc139db 改名 2021-11-04 18:42:58 +08:00
as2252258 283c7c2371 改名 2021-11-04 18:42:26 +08:00
as2252258 0b170cafb2 改名 2021-11-04 18:42:05 +08:00
as2252258 d036f730ca 改名 2021-11-04 18:39:35 +08:00
as2252258 55727bb219 改名 2021-11-04 18:38:06 +08:00
as2252258 dc477978d3 改名 2021-11-04 18:37:31 +08:00
as2252258 7dda29a892 改名 2021-11-04 18:37:01 +08:00
as2252258 567cac606a 改名 2021-11-04 18:36:38 +08:00
as2252258 49d435e4a5 改名 2021-11-04 18:36:17 +08:00
as2252258 5303c05274 改名 2021-11-04 18:34:19 +08:00
as2252258 f6cb258259 改名 2021-11-04 18:33:57 +08:00
as2252258 affb161ddf 改名 2021-11-04 18:29:52 +08:00
as2252258 a80f671a22 改名 2021-11-04 18:29:29 +08:00
as2252258 497cd95731 改名 2021-11-04 18:27:41 +08:00
as2252258 3ae85beb16 改名 2021-11-04 18:25:03 +08:00
as2252258 0a76e991b9 改名 2021-11-04 18:24:42 +08:00
as2252258 bfc591b10a 改名 2021-11-04 18:23:58 +08:00
as2252258 b274140708 改名 2021-11-04 18:23:24 +08:00
as2252258 a4a9a5618d 改名 2021-11-04 18:22:42 +08:00
as2252258 0cf17a547e 改名 2021-11-04 18:21:29 +08:00
as2252258 35ea526420 改名 2021-11-04 18:16:34 +08:00
as2252258 8ba04b4ccc 改名 2021-11-04 18:15:56 +08:00
as2252258 b83a0c4c96 改名 2021-11-04 18:09:13 +08:00
as2252258 21d3738125 改名 2021-11-04 18:06:45 +08:00
as2252258 2bd18b014d 改名 2021-11-04 18:06:10 +08:00
as2252258 39be8f4b3b 改名 2021-11-04 18:03:24 +08:00
as2252258 043b62688b 改名 2021-11-04 18:02:33 +08:00
as2252258 38f5f57c4d 改名 2021-11-04 17:59:04 +08:00
as2252258 2c7a755663 改名 2021-11-04 17:58:56 +08:00
as2252258 187b4311eb 改名 2021-11-04 17:56:39 +08:00
as2252258 7d2c2cf7ff 改名 2021-11-04 17:48:27 +08:00
as2252258 3771a8fb22 改名 2021-11-04 17:47:50 +08:00
as2252258 7561bacda5 改名 2021-11-04 17:46:44 +08:00
as2252258 c7d6032010 改名 2021-11-04 17:45:53 +08:00
as2252258 48d9c5ce79 改名 2021-11-04 17:40:11 +08:00
as2252258 b9d2288ac7 改名 2021-11-04 17:38:37 +08:00
as2252258 13877c6d58 改名 2021-11-04 17:37:38 +08:00
as2252258 320a01d822 改名 2021-11-04 17:34:20 +08:00
as2252258 a435df8453 改名 2021-11-04 17:33:41 +08:00
7 changed files with 121 additions and 75 deletions
@@ -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.");
+4 -2
View File
@@ -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
+57 -54
View File
@@ -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]);
}
}
+2
View File
@@ -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);
});
}
}
+8
View File
@@ -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();
}
/**
+9 -1
View File
@@ -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;
}