modifs.mineures sans commentaires
This commit is contained in:
parent
a099261b58
commit
fe5ed584b4
|
@ -8,7 +8,7 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/nur_src" isTestSource="false" packagePrefix="nur\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/nur_tests" isTestSource="true" packagePrefix="nur\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/wip" isTestSource="false" packagePrefix="nur\sery\wip\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/wip_app" isTestSource="false" packagePrefix="nur\sery\app\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/wip_app" isTestSource="false" packagePrefix="nur\sery\" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
|
|
@ -50,8 +50,7 @@
|
|||
"autoload": {
|
||||
"psr-4": {
|
||||
"nur\\sery\\wip\\": "wip",
|
||||
"nur\\sery\\app\\": "wip_app",
|
||||
"nur\\sery\\": "src",
|
||||
"nur\\sery\\": ["wip_app", "src"],
|
||||
"nur\\": "nur_src"
|
||||
},
|
||||
"files": [
|
||||
|
|
|
@ -9,25 +9,18 @@ use nur\config\ArrayConfig;
|
|||
use nur\msg;
|
||||
use nur\os;
|
||||
use nur\path;
|
||||
use nur\sery\app\launcher;
|
||||
use nur\sery\app\RunFile;
|
||||
use nur\sery\cl;
|
||||
use nur\sery\app;
|
||||
use nur\sery\app\RunFile;
|
||||
use nur\sery\output\console as nconsole;
|
||||
use nur\sery\output\log as nlog;
|
||||
use nur\sery\output\msg as nmsg;
|
||||
use nur\sery\output\console as nconsole;
|
||||
use nur\sery\output\std\StdMessenger;
|
||||
use nur\yaml;
|
||||
|
||||
/**
|
||||
* Class Application: application de base
|
||||
*/
|
||||
abstract class Application {
|
||||
protected static ?array $internal_use_app_params = null;
|
||||
|
||||
static function internal_use_set_app_params($params) {
|
||||
self::$internal_use_app_params = $params;
|
||||
}
|
||||
|
||||
/** @var string répertoire du projet (celui qui contient composer.json */
|
||||
const PROJDIR = null;
|
||||
|
||||
|
@ -46,6 +39,13 @@ abstract class Application {
|
|||
*/
|
||||
const APPCODE = null;
|
||||
|
||||
/**
|
||||
* @var string|null identifiant d'un groupe auquel l'application appartient.
|
||||
* les applications du même groupe enregistrent leur fichiers de controle au
|
||||
* même endroit $VARDIR/$APPGROUP
|
||||
*/
|
||||
const APPGROUP = null;
|
||||
|
||||
/**
|
||||
* @var string code de l'application, utilisé pour inférer le nom de certains
|
||||
* fichiers spécifiques à l'application.
|
||||
|
@ -78,7 +78,74 @@ abstract class Application {
|
|||
const USE_RUNLOCK = false;
|
||||
|
||||
/** @var bool faut-il installer le gestionnaire de signaux? */
|
||||
const USE_SIGNAL_HANDLER = false;
|
||||
const INSTALL_SIGNAL_HANDLER = false;
|
||||
|
||||
private static function _info(string $message, int $ec=0): int {
|
||||
fwrite(STDERR, "INFO: $message\n");
|
||||
return $ec;
|
||||
}
|
||||
|
||||
private static function _error(string $message, int $ec=1): int {
|
||||
fwrite(STDERR, "ERROR: $message\n");
|
||||
return $ec;
|
||||
}
|
||||
|
||||
static function _manage_runfile(int &$argc, array &$argv, RunFile $runfile): void {
|
||||
if ($argc <= 1 || $argv[1] !== "//") return;
|
||||
array_splice($argv, 1, 1); $argc--;
|
||||
$ec = 0;
|
||||
switch ($argv[1] ?? "infos") {
|
||||
case "help":
|
||||
self::_info(<<<EOT
|
||||
Valid commands:
|
||||
infos
|
||||
dump
|
||||
reset
|
||||
release
|
||||
start
|
||||
kill
|
||||
|
||||
EOT);
|
||||
break;
|
||||
case "infos":
|
||||
case "i":
|
||||
$desc = $runfile->getDesc();
|
||||
if ($runfile->isRunning()) {
|
||||
$actionDesc = $runfile->getActionDesc();
|
||||
if ($actionDesc !== null) $actionDesc = "\n$actionDesc";
|
||||
echo "$desc$actionDesc\n";
|
||||
} else {
|
||||
echo "$desc\n";
|
||||
$ec = 1;
|
||||
}
|
||||
break;
|
||||
case "dump":
|
||||
case "d":
|
||||
yaml::dump($runfile->read());
|
||||
break;
|
||||
case "reset":
|
||||
case "z":
|
||||
if (!$runfile->isRunning()) $runfile->reset();
|
||||
else $ec = self::_error("cannot reset while running");
|
||||
break;
|
||||
case "release":
|
||||
case "rl":
|
||||
$runfile->release();
|
||||
break;
|
||||
case "start":
|
||||
case "s":
|
||||
array_splice($argv, 1, 1); $argc--;
|
||||
return;
|
||||
case "kill":
|
||||
case "k":
|
||||
if ($runfile->isRunning()) $runfile->wfKill();
|
||||
else $ec = self::_error("not running");
|
||||
break;
|
||||
default:
|
||||
$ec = self::_error("$argv[1]: unexpected command", app::EC_BAD_COMMAND);
|
||||
}
|
||||
exit($ec);
|
||||
}
|
||||
|
||||
protected static function _app_init(): void {
|
||||
config::set_fact(config::FACT_CLI_APP);
|
||||
|
@ -108,7 +175,7 @@ abstract class Application {
|
|||
if ($projdir == "/") break;
|
||||
}
|
||||
|
||||
app::init(static::class, self::$internal_use_app_params);
|
||||
app::init(static::class);
|
||||
nmsg::set_messenger(new StdMessenger([
|
||||
"min_level" => nmsg::DEBUG,
|
||||
]));
|
||||
|
@ -146,7 +213,7 @@ abstract class Application {
|
|||
static function run(?Application $app=null): void {
|
||||
$unlock = false;
|
||||
$stop = false;
|
||||
$shutdownHandler = function () use (&$unlock, &$stop) {
|
||||
$shutdown = function () use (&$unlock, &$stop) {
|
||||
if ($unlock) {
|
||||
app::get()->getRunfile()->release();
|
||||
$unlock = false;
|
||||
|
@ -156,29 +223,19 @@ abstract class Application {
|
|||
$stop = false;
|
||||
}
|
||||
};
|
||||
register_shutdown_function($shutdownHandler);
|
||||
if (static::USE_SIGNAL_HANDLER) {
|
||||
$signalHandler = function(int $signo, $siginfo) {
|
||||
self::exit(255);
|
||||
};
|
||||
pcntl_signal(SIGHUP, $signalHandler);
|
||||
pcntl_signal(SIGINT, $signalHandler);
|
||||
pcntl_signal(SIGQUIT, $signalHandler);
|
||||
pcntl_signal(SIGTERM, $signalHandler);
|
||||
}
|
||||
register_shutdown_function($shutdown);
|
||||
app::install_signal_handler(static::INSTALL_SIGNAL_HANDLER);
|
||||
try {
|
||||
static::_app_init();
|
||||
if (static::USE_RUNFILE) {
|
||||
$useRunfile = static::USE_RUNFILE;
|
||||
$useRunlock = static::USE_RUNLOCK;
|
||||
if ($useRunfile) {
|
||||
$runfile = app::get()->getRunfile();
|
||||
|
||||
global $argc, $argv;
|
||||
if ($argc === 2 && ($argv[1] === "--Application-release-runlock" || $argv[1] === "--ARL")) {
|
||||
$runfile->release();
|
||||
exit(0);
|
||||
}
|
||||
$useRunlock = static::USE_RUNLOCK;
|
||||
if ($useRunlock && $runfile->warnIfLocked()) {
|
||||
exit(1);
|
||||
}
|
||||
self::_manage_runfile($argc, $argv, $runfile);
|
||||
if ($useRunlock && $runfile->warnIfLocked()) exit(app::EC_LOCKED);
|
||||
|
||||
$runfile->wfStart();
|
||||
$stop = true;
|
||||
if ($useRunlock) {
|
||||
|
@ -393,15 +450,4 @@ abstract class Application {
|
|||
}
|
||||
|
||||
abstract function main();
|
||||
|
||||
const BGLAUNCH_SCRIPT = null;
|
||||
static function runfile(): RunFile {
|
||||
$callerParams = app::get()->getParams();
|
||||
return app::with(static::class, $callerParams)->getRunfile();
|
||||
}
|
||||
static function bglaunch(?array $args=null) {
|
||||
launcher::launch(static::class, cl::merge([
|
||||
static::BGLAUNCH_SCRIPT,
|
||||
], $args));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
namespace nur\sery;
|
||||
|
||||
use nur\cli\Application as nur_Application;
|
||||
use nur\sery\app\cli\Application;
|
||||
use nur\sery\app\LockFile;
|
||||
use nur\sery\app\RunFile;
|
||||
|
@ -11,7 +12,8 @@ use nur\sery\php\func;
|
|||
class app {
|
||||
private static function isa_Application($app): bool {
|
||||
if (!is_string($app)) return false;
|
||||
return $app === Application::class || is_subclass_of($app, Application::class);
|
||||
return $app === Application::class || is_subclass_of($app, Application::class)
|
||||
|| $app === nur_Application::class || is_subclass_of($app, nur_Application::class);
|
||||
}
|
||||
|
||||
private static function get_params($app): array {
|
||||
|
@ -525,9 +527,8 @@ class app {
|
|||
* afficher une erreur et quitter l'application
|
||||
*/
|
||||
static function check_bgapplication_enabled(bool $forceEnabled=false): void {
|
||||
if (self::$bgapplication_enabled === null) return;
|
||||
$enabled = boolval(self::$bgapplication_enabled->invoke());
|
||||
if (!$forceEnabled && !$enabled) {
|
||||
if (self::$bgapplication_enabled === null || $forceEnabled) return;
|
||||
if (!self::$bgapplication_enabled->invoke()) {
|
||||
throw new ExitError(self::EC_DISABLED, "Planifications désactivées. La tâche n'a pas été lancée");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue