diff --git a/CHANGELOG.md b/CHANGELOG.md index cc897da..eb7f497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,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. +* (improvement) Add explicit task class field. 2.3.2 diff --git a/src/Command/TaskLogCommand.php b/src/Command/TaskLogCommand.php index f20a850..fc9438e 100644 --- a/src/Command/TaskLogCommand.php +++ b/src/Command/TaskLogCommand.php @@ -138,7 +138,7 @@ private function showTaskDetails (TorrStyle $io, int $taskId) : int ["Task ID" => $task->id], ["Task" => $task->getTaskLabel()], ["Status" => $status], - ["Task Class" => $task->getTaskClass()], + ["Task Class" => $task->taskClass], ["Runs" => \count($task->runs)], ["Total Duration" => $this->formatDuration($task->getTotalDuration())], ["Handled by" => implode(" on ", $handled)], @@ -218,7 +218,7 @@ private function showList (TorrStyle $io, int $limit) : void $task->getTaskLabel() ?? "—", ), $status, - $task->getTaskClass(), + $task->taskClass, \count($task->runs), $this->formatDuration($task->getTotalDuration()), $task->timeQueued->format("c"), diff --git a/src/Entity/TaskLog.php b/src/Entity/TaskLog.php index c341968..78b7310 100644 --- a/src/Entity/TaskLog.php +++ b/src/Entity/TaskLog.php @@ -14,7 +14,6 @@ /** * @phpstan-type TaskDetails array{ - * "class"?: class-string|null, * "handledBy"?: string|null, * "label"?: string, * "task"?: string, @@ -40,6 +39,12 @@ class TaskLog #[ORM\Column(type: Types::STRING, length: 50, unique: true)] public private(set) string $taskId; + /** + * + */ + #[ORM\Column(type: Types::STRING, length: 1000)] + public string $taskClass; + /** * The encoded task details * @@ -65,6 +70,7 @@ public function __construct ( Task $task, ) { + $this->taskClass = $task::class; $this->taskId = $task->ulid; $this->runs = new ArrayCollection(); $this->timeQueued = now(); @@ -257,9 +263,11 @@ public function getTransport () : ?string /** * Returns the class of the message + * + * @deprecated use the property directly instead */ - public function getTaskClass () : ?string + public function getTaskClass () : string { - return $this->getTaskDetails()["class"] ?? null; + return $this->taskClass; } } diff --git a/src/Entity/TaskRun.php b/src/Entity/TaskRun.php index 6655617..6aa7ec9 100644 --- a/src/Entity/TaskRun.php +++ b/src/Entity/TaskRun.php @@ -56,6 +56,9 @@ class TaskRun */ #[ORM\Column(type: Types::TEXT, nullable: true)] public private(set) ?string $output = null; + + /** + */ public bool $isFinished { get => null !== $this->duration; } @@ -65,7 +68,7 @@ class TaskRun */ public function __construct ( TaskLog $taskLog, - private ?LoggerInterface $logger = null, + private readonly ?LoggerInterface $logger = null, ) { $this->taskLog = $taskLog; diff --git a/src/Normalizer/TaskDetailsNormalizer.php b/src/Normalizer/TaskDetailsNormalizer.php index bcc4b66..8f2845b 100644 --- a/src/Normalizer/TaskDetailsNormalizer.php +++ b/src/Normalizer/TaskDetailsNormalizer.php @@ -22,7 +22,6 @@ public function normalizeTaskDetails (Envelope $envelope) : array /** @phpstan-var TaskDetails $details */ $details = [ - "class" => $task::class, "transport" => $envelope->last(ReceivedStamp::class)?->getTransportName(), "handledBy" => $envelope->last(HandledStamp::class)?->getHandlerName(), ];