From f61b098b3e4fa8f009fae9282d94a145b0e5212d Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 30 Sep 2024 18:46:08 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- nur_src/cli/Application.php | 10 +-- src/app/RunFile.php | 111 ++++++++++++++++++++------------ wip_app/app/cli/Application.php | 10 +-- 3 files changed, 75 insertions(+), 56 deletions(-) diff --git a/nur_src/cli/Application.php b/nur_src/cli/Application.php index 9fa7749..379928b 100644 --- a/nur_src/cli/Application.php +++ b/nur_src/cli/Application.php @@ -111,14 +111,8 @@ EOT); 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; - } + echo implode("\n", $desc["message"])."\n"; + $ec = $desc["exitcode"] ?? 0; break; case "dump": case "d": diff --git a/src/app/RunFile.php b/src/app/RunFile.php index b6dbe48..29e4cae 100644 --- a/src/app/RunFile.php +++ b/src/app/RunFile.php @@ -380,32 +380,6 @@ class RunFile { return $done; } - function getDesc(?array $data=null): ?string { - $data ??= $this->read(); - $desc = $data["name"]; - $dateStart = $data["date_start"]; - $dateStop = $data["date_stop"]; - $exitcode = $data["exitcode"]; - if ($exitcode !== null) $exitcode = "\nCode de retour $exitcode"; - if (!$this->wasStarted($data)) { - return "$desc: pas encore démarré"; - } elseif ($this->isRunning($data)) { - $sinceStart = Elapsed::format_since($dateStart); - $started = "\nDémarré depuis $dateStart ($sinceStart)"; - return "$desc: EN COURS pid $data[pid]$started"; - } elseif ($this->isStopped($data)) { - $duration = "\nDurée ".Elapsed::format_delay($dateStart, $dateStop); - $sinceStop = Elapsed::format_since($dateStop); - $stopped = "\nArrêtée $sinceStop le $dateStop"; - $reaped = $data["is_reaped"]? ", reaped": null; - $done = $data["is_ack_done"]? ", ACK done": null; - return "$desc: TERMINEE$duration$stopped$exitcode$reaped$done"; - } else { - $stopped = $dateStop? "\nArrêtée le $dateStop": null; - return "$desc: CRASHED\nCommencé le $dateStart$stopped$exitcode"; - } - } - #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # gestion des actions @@ -433,9 +407,24 @@ class RunFile { app::_dispatch_signals(); } - function getActionDesc(?array $data=null): ?string { + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Divers + + function getLockFile(?string $name=null, ?string $title=null): LockFile { + $ext = self::LOCK_EXT; + if ($name !== null) $ext = ".$name$ext"; + $file = path::ensure_ext($this->file->getFile(), $ext, self::RUN_EXT); + $name = str::join("/", [$this->name, $name]); + return new LockFile($file, $name, $title); + } + + function getDesc(?array $data=null, bool $withAction=true): ?array { $data ??= $this->read(); - $action = $data["action"]; + $desc = $data["name"]; + $dateStart = $data["date_start"]; + $action = $withAction? $data["action"]: null; + $dateStop = $data["date_stop"]; + $exitcode = $data["exitcode"]; if ($action !== null) { $date ??= $data["action_date_step"]; $date ??= $data["action_date_start"]; @@ -449,17 +438,59 @@ class RunFile { $action .= " ($current)"; } } - return $action; - } - - #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - # Divers - - function getLockFile(?string $name=null, ?string $title=null): LockFile { - $ext = self::LOCK_EXT; - if ($name !== null) $ext = ".$name$ext"; - $file = path::ensure_ext($this->file->getFile(), $ext, self::RUN_EXT); - $name = str::join("/", [$this->name, $name]); - return new LockFile($file, $name, $title); + if ($exitcode !== null) { + $result = ["Code de retour $exitcode"]; + if ($data["is_reaped"]) $result[] = "reaped"; + if ($data["is_ack_done"]) $result[] = "acknowledged"; + $result = join(", ", $result); + } else { + $result = null; + } + if (!$this->wasStarted($data)) { + $type = "neutral"; + $haveLog = false; + $exitcode = null; + $message = [ + "status" => "$desc: pas encore démarré", + ]; + } elseif ($this->isRunning($data)) { + $sinceStart = Elapsed::format_since($dateStart); + $type = "info"; + $haveLog = true; + $exitcode = null; + $message = [ + "status" => "$desc: EN COURS pid $data[pid]", + "started" => "Démarrée depuis $dateStart ($sinceStart)", + "action" => $action, + ]; + } elseif ($this->isStopped($data)) { + $duration = "\nDurée ".Elapsed::format_delay($dateStart, $dateStop); + $sinceStop = Elapsed::format_since($dateStop); + $haveLog = true; + if ($exitcode === null) $type = "warning"; + elseif ($exitcode === 0) $type = "success"; + else $type = "danger"; + $message = [ + "status" => "$desc: TERMINEE$duration", + "stopped" => "Arrêtée $sinceStop le $dateStop", + "result" => $result, + ]; + } else { + $type = "warning"; + $haveLog = true; + $exitcode = null; + $message = [ + "status" => "$desc: ETAT INCONNU", + "started" => "Commencée le $dateStart", + "stopped" => $dateStop? "Arrêtée le $dateStop": null, + "exitcode" => $result !== null? "Code de retour $result": null, + ]; + } + return [ + "type" => $type, + "have_log" => $haveLog, + "exitcode" => $exitcode, + "message" => array_filter($message), + ]; } } diff --git a/wip_app/app/cli/Application.php b/wip_app/app/cli/Application.php index 4944637..4b381c6 100644 --- a/wip_app/app/cli/Application.php +++ b/wip_app/app/cli/Application.php @@ -112,14 +112,8 @@ EOT); 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; - } + echo implode("\n", $desc["message"])."\n"; + $ec = $desc["exitcode"] ?? 0; break; case "dump": case "d":