modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-09-30 18:46:08 +04:00
parent a257eeb478
commit f61b098b3e
3 changed files with 75 additions and 56 deletions

View File

@ -111,14 +111,8 @@ EOT);
case "infos": case "infos":
case "i": case "i":
$desc = $runfile->getDesc(); $desc = $runfile->getDesc();
if ($runfile->isRunning()) { echo implode("\n", $desc["message"])."\n";
$actionDesc = $runfile->getActionDesc(); $ec = $desc["exitcode"] ?? 0;
if ($actionDesc !== null) $actionDesc = "\n$actionDesc";
echo "$desc$actionDesc\n";
} else {
echo "$desc\n";
$ec = 1;
}
break; break;
case "dump": case "dump":
case "d": case "d":

View File

@ -380,32 +380,6 @@ class RunFile {
return $done; 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 # gestion des actions
@ -433,9 +407,24 @@ class RunFile {
app::_dispatch_signals(); 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(); $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) { if ($action !== null) {
$date ??= $data["action_date_step"]; $date ??= $data["action_date_step"];
$date ??= $data["action_date_start"]; $date ??= $data["action_date_start"];
@ -449,17 +438,59 @@ class RunFile {
$action .= " ($current)"; $action .= " ($current)";
} }
} }
return $action; if ($exitcode !== null) {
} $result = ["Code de retour $exitcode"];
if ($data["is_reaped"]) $result[] = "reaped";
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if ($data["is_ack_done"]) $result[] = "acknowledged";
# Divers $result = join(", ", $result);
} else {
function getLockFile(?string $name=null, ?string $title=null): LockFile { $result = null;
$ext = self::LOCK_EXT; }
if ($name !== null) $ext = ".$name$ext"; if (!$this->wasStarted($data)) {
$file = path::ensure_ext($this->file->getFile(), $ext, self::RUN_EXT); $type = "neutral";
$name = str::join("/", [$this->name, $name]); $haveLog = false;
return new LockFile($file, $name, $title); $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),
];
} }
} }

View File

@ -112,14 +112,8 @@ EOT);
case "infos": case "infos":
case "i": case "i":
$desc = $runfile->getDesc(); $desc = $runfile->getDesc();
if ($runfile->isRunning()) { echo implode("\n", $desc["message"])."\n";
$actionDesc = $runfile->getActionDesc(); $ec = $desc["exitcode"] ?? 0;
if ($actionDesc !== null) $actionDesc = "\n$actionDesc";
echo "$desc$actionDesc\n";
} else {
echo "$desc\n";
$ec = 1;
}
break; break;
case "dump": case "dump":
case "d": case "d":