diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a01f77..cc897da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * (improvement) Simplify task run duration calculation. * (improvement) Transform exception to log entry, so that the worker doesn't constantly fail. +* (deprecation) Deprecate entity getters in favor of properties. 2.3.2 diff --git a/src/Command/TaskLogCommand.php b/src/Command/TaskLogCommand.php index 8844114..f20a850 100644 --- a/src/Command/TaskLogCommand.php +++ b/src/Command/TaskLogCommand.php @@ -135,25 +135,25 @@ private function showTaskDetails (TorrStyle $io, int $taskId) : int } $io->definitionList( - ["Task ID" => $task->getId()], + ["Task ID" => $task->id], ["Task" => $task->getTaskLabel()], ["Status" => $status], - ["Task Class" => $task->getTaskClass() ?? "—"], - ["Runs" => \count($task->getRuns())], + ["Task Class" => $task->getTaskClass()], + ["Runs" => \count($task->runs)], ["Total Duration" => $this->formatDuration($task->getTotalDuration())], ["Handled by" => implode(" on ", $handled)], - ["Registered" => $task->getTimeQueued()->format("c")], + ["Registered" => $task->timeQueued->format("c")], ); - $index = \count($task->getRuns()); + $index = \count($task->runs); - foreach ($task->getRuns() as $run) + foreach ($task->runs as $run) { $status = "running"; - if ($run->isFinished()) + if ($run->isFinished) { - $status = $run->isSuccess() + $status = $run->success ? "succeeded" : "failed"; } @@ -165,19 +165,19 @@ private function showTaskDetails (TorrStyle $io, int $taskId) : int )); $io->writeln(\sprintf( "Started: %s", - $run->getTimeStarted()->format("c"), + $run->timeStarted->format("c"), )); - if ($run->isFinished()) + if ($run->isFinished) { $io->writeln(\sprintf( "Duration: %s", - $this->formatDuration((float) $run->getDuration()), + $this->formatDuration((float) $run->duration), )); $io->writeln("Output:"); $io->newLine(); $io->writeln("------------------"); - $io->writeln((string) $run->getOutput()); + $io->writeln((string) $run->output); $io->writeln("------------------"); } @@ -211,17 +211,17 @@ private function showList (TorrStyle $io, int $limit) : void } $rows[] = [ - $task->getId(), + $task->id, \sprintf( "%s", null !== $task->getTaskLabel() ? "yellow" : "gray", $task->getTaskLabel() ?? "—", ), $status, - $task->getTaskClass() ?? "—", - \count($task->getRuns()), + $task->getTaskClass(), + \count($task->runs), $this->formatDuration($task->getTotalDuration()), - $task->getTimeQueued()->format("c"), + $task->timeQueued->format("c"), ]; } $rows[] = [ diff --git a/src/Entity/TaskLog.php b/src/Entity/TaskLog.php index dedcb71..c341968 100644 --- a/src/Entity/TaskLog.php +++ b/src/Entity/TaskLog.php @@ -32,13 +32,13 @@ class TaskLog #[ORM\Id] #[ORM\GeneratedValue(strategy: "AUTO")] #[ORM\Column(name: "id", type: Types::INTEGER)] - private ?int $id = null; + public private(set) ?int $id = null; /** * ULIDs have only 22 characters, but just to be sure */ #[ORM\Column(type: Types::STRING, length: 50, unique: true)] - private string $taskId; + public private(set) string $taskId; /** * The encoded task details @@ -52,12 +52,12 @@ class TaskLog * */ #[ORM\Column(name: "time_queued", type: Types::DATETIMETZ_IMMUTABLE)] - private \DateTimeImmutable $timeQueued; + public private(set) \DateTimeImmutable $timeQueued; /** @var Collection */ #[ORM\OneToMany(mappedBy: "taskLog", targetEntity: TaskRun::class, cascade: ["remove"], orphanRemoval: true)] #[ORM\OrderBy(["timeStarted" => "asc"])] - private Collection $runs; + public private(set) Collection $runs; /** */ @@ -71,6 +71,7 @@ public function __construct ( } /** + * @deprecated use the property directly instead */ public function getId () : ?int { @@ -78,6 +79,7 @@ public function getId () : ?int } /** + * @deprecated use the property directly instead */ public function getTaskId () : string { @@ -85,6 +87,7 @@ public function getTaskId () : string } /** + * @deprecated use the property directly instead */ public function getTimeQueued () : \DateTimeImmutable { @@ -93,6 +96,8 @@ public function getTimeQueued () : \DateTimeImmutable /** * @return Collection + * + * @deprecated use the property directly instead */ public function getRuns () : Collection { @@ -106,7 +111,7 @@ public function isSuccess () : bool { foreach ($this->runs as $run) { - if ($run->isSuccess()) + if ($run->success) { return true; } @@ -121,7 +126,7 @@ public function getLastUnfinishedRun () : ?TaskRun { foreach ($this->runs as $run) { - if (!$run->isFinished()) + if (!$run->isFinished) { return $run; } @@ -202,12 +207,12 @@ public function getStatus () : ?bool foreach ($this->runs as $run) { - if (!$run->isFinished()) + if (!$run->isFinished) { continue; } - if ($run->isSuccess()) + if ($run->success) { return true; } @@ -228,7 +233,7 @@ public function getTotalDuration () : float foreach ($this->runs as $run) { - $duration += (float) $run->getDuration(); + $duration += (float) $run->duration; } return $duration; diff --git a/src/Entity/TaskRun.php b/src/Entity/TaskRun.php index 4168c8a..6655617 100644 --- a/src/Entity/TaskRun.php +++ b/src/Entity/TaskRun.php @@ -22,40 +22,43 @@ class TaskRun #[ORM\Id] #[ORM\GeneratedValue(strategy: "AUTO")] #[ORM\Column(name: "id", type: Types::INTEGER)] - private ?int $id = null; + public private(set) ?int $id = null; /** */ #[ORM\ManyToOne(targetEntity: TaskLog::class, inversedBy: "runs")] #[ORM\JoinColumn(name: "task_log_id", referencedColumnName: "id", nullable: false)] - private TaskLog $taskLog; + public private(set) TaskLog $taskLog; /** * */ #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] - private \DateTimeImmutable $timeStarted; + public private(set) \DateTimeImmutable $timeStarted; /** * */ #[ORM\Column(type: Types::FLOAT, nullable: true)] - private ?float $duration = null; + public private(set) ?float $duration = null; /** */ #[ORM\Column(type: Types::BOOLEAN, nullable: true)] - private ?bool $success = null; + public private(set) ?bool $success = null; /** */ #[ORM\Column(type: Types::BOOLEAN, nullable: true)] - private ?bool $finishedProperly = null; + public private(set) ?bool $finishedProperly = null; /** */ #[ORM\Column(type: Types::TEXT, nullable: true)] - private ?string $output = null; + public private(set) ?string $output = null; + public bool $isFinished { + get => null !== $this->duration; + } // endregion /** @@ -71,6 +74,7 @@ public function __construct ( // region Accessors /** + * @deprecated use the property directly instead */ public function getTaskLog () : TaskLog { @@ -78,6 +82,7 @@ public function getTaskLog () : TaskLog } /** + * @deprecated use the property directly instead */ public function getTimeStarted () : \DateTimeImmutable { @@ -85,7 +90,9 @@ public function getTimeStarted () : \DateTimeImmutable } /** - * Whether the task was finished successfully. + * @deprecated use the property directly instead + * + * Whether the task was finished successfully * * @return bool|null Whether the task was finished successfully. Will return null if not yet finished. */ @@ -95,6 +102,7 @@ public function isSuccess () : ?bool } /** + * @deprecated use the property directly instead */ public function getOutput () : ?string { @@ -102,6 +110,7 @@ public function getOutput () : ?string } /** + * @deprecated use the property directly instead */ public function isFinished () : bool { @@ -110,6 +119,8 @@ public function isFinished () : bool /** * The duration of the run in nanoseconds (if the task is finished already) + * + * @deprecated use the property directly instead */ public function getDuration () : ?float { @@ -157,7 +168,7 @@ private function finalizeRun ( ?string $output = null, ) : void { - if ($this->isFinished()) + if ($this->isFinished) { $this->logger?->error("Can't finalize task run {id} as it is already finished.", [ "id" => $this->id, diff --git a/src/Log/LogCleaner.php b/src/Log/LogCleaner.php index 854babf..a8a00c1 100644 --- a/src/Log/LogCleaner.php +++ b/src/Log/LogCleaner.php @@ -26,7 +26,7 @@ public function cleanLogEntries () : array $deleted[] = \sprintf( "%s (%s)", $logEntry->getTaskLabel(), - $logEntry->getTimeQueued()->format("c"), + $logEntry->timeQueued->format("c"), ); $this->model->remove($logEntry); diff --git a/src/Model/TaskLogModel.php b/src/Model/TaskLogModel.php index 8843266..7500d81 100644 --- a/src/Model/TaskLogModel.php +++ b/src/Model/TaskLogModel.php @@ -103,9 +103,9 @@ public function fetchOutdatedTasks ( // TTL. If so, then adjust the purge date, to fulfill both $cutOffEntry = $this->getCutoffEntry($maxEntries); - if (null !== $cutOffEntry && $cutOffEntry->getTimeQueued() > $purgeBefore) + if (null !== $cutOffEntry && $cutOffEntry->timeQueued > $purgeBefore) { - $purgeBefore = $cutOffEntry->getTimeQueued(); + $purgeBefore = $cutOffEntry->timeQueued; } /** @var TaskLog[] $entries */