From c8d05cb5405b1ac19803a8c83cd717669eeeccac Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Mon, 21 Sep 2026 16:55:57 +0200 Subject: [PATCH 1/5] =?UTF-8?q?Add=20proper=20support=20for=20fetching=20a?= =?UTF-8?q?nd=20validating=20Tasks=20that=20are=20configured=20via=20`#[As?= =?UTF-8?q?Message(=E2=80=A6)]`=20attribute.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../FindTaskClassesCompilerPass.php | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6837637..e6b25a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ vNext ===== * (impprovement) Display class name of wrapped Task when running `sf debug:scheduler` +* (bug) Add proper support for fetching and validating Tasks that are configured via `#[AsMessage(…)]` attribute. 3.4.1 diff --git a/src/DependencyInjection/FindTaskClassesCompilerPass.php b/src/DependencyInjection/FindTaskClassesCompilerPass.php index 970d2c0..b24f0e9 100644 --- a/src/DependencyInjection/FindTaskClassesCompilerPass.php +++ b/src/DependencyInjection/FindTaskClassesCompilerPass.php @@ -5,6 +5,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Torr\TaskManager\Config\BundleConfig; +use Torr\TaskManager\Task\Task; /** * Compiler pass, that collects all tasks from the container that are from the app @@ -22,20 +23,27 @@ public function process (ContainerBuilder $container) : void { $taskClasses = []; - foreach ($container->findTaggedServiceIds("task-manager.task") as $taskServiceId => $config) + foreach ($container->getDefinitions() as $definition) { - $definition = $container->getDefinition($taskServiceId); $taskFQCN = $definition->getClass(); if (null !== $taskFQCN && str_starts_with($taskFQCN, "App\\")) { + $reflection = $container->getReflectionClass($taskFQCN, false); + + if (null === $reflection || !$reflection->isSubclassOf(Task::class)) + { + continue; + } + $taskClasses[] = $taskFQCN; - } - // Remove task service definition, as these must never be a service - // in the actual runtime. We just use the mechanism to collect all - // tasks in the app. - $container->removeDefinition($taskServiceId); + // Ensure that our Task classes are removed from the container definitions. Depending on the way + // the Tasks are registered (either via `AsMessage` attribute or via `messenger.yaml` config), + // they'll be excluded automatically. This happens automatically when the `AsMessage` attribute is being used. + // Here we're making sure that this also happens when using the YAML config file. + $definition->addTag("container.excluded"); + } } $container->getDefinition(BundleConfig::class) From 5ebd7eda003a789299035e3e69498cb47d952c17 Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Mon, 21 Sep 2026 17:01:05 +0200 Subject: [PATCH 2/5] Reduce nesting --- .../FindTaskClassesCompilerPass.php | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/DependencyInjection/FindTaskClassesCompilerPass.php b/src/DependencyInjection/FindTaskClassesCompilerPass.php index b24f0e9..1278ae3 100644 --- a/src/DependencyInjection/FindTaskClassesCompilerPass.php +++ b/src/DependencyInjection/FindTaskClassesCompilerPass.php @@ -23,27 +23,29 @@ public function process (ContainerBuilder $container) : void { $taskClasses = []; - foreach ($container->getDefinitions() as $definition) + foreach ($container->getDefinitions() as $taskServiceId => $definition) { $taskFQCN = $definition->getClass(); - if (null !== $taskFQCN && str_starts_with($taskFQCN, "App\\")) + if (null === $taskFQCN || !str_starts_with($taskFQCN, "App\\")) { - $reflection = $container->getReflectionClass($taskFQCN, false); - - if (null === $reflection || !$reflection->isSubclassOf(Task::class)) - { - continue; - } + continue; + } - $taskClasses[] = $taskFQCN; + $reflection = $container->getReflectionClass($taskFQCN, false); - // Ensure that our Task classes are removed from the container definitions. Depending on the way - // the Tasks are registered (either via `AsMessage` attribute or via `messenger.yaml` config), - // they'll be excluded automatically. This happens automatically when the `AsMessage` attribute is being used. - // Here we're making sure that this also happens when using the YAML config file. - $definition->addTag("container.excluded"); + if (null === $reflection || !$reflection->isSubclassOf(Task::class)) + { + continue; } + + $taskClasses[] = $taskFQCN; + + // Ensure that our Task classes are removed from the container definitions. Depending on the way + // the Tasks are registered (either via `AsMessage` attribute or via `messenger.yaml` config), + // they'll be excluded automatically. This happens automatically when the `AsMessage` attribute is being used. + // Here we're making sure that this also happens when using the YAML config file. + $definition->addTag("container.excluded"); } $container->getDefinition(BundleConfig::class) From 0c554a37778101333f55e895a21e2637867aa938 Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Mon, 21 Sep 2026 17:02:14 +0200 Subject: [PATCH 3/5] Remove auto-tag `task-manager.task` This tag was previously only used for fetching Tasks during ContainerBuild, which has now been replaced by a different method that works better for Tasks that have been registered either via `#[AsMessage]` or `messenger.yaml` config --- src/TaskManagerBundle.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/TaskManagerBundle.php b/src/TaskManagerBundle.php index 190d4d9..b8f8910 100644 --- a/src/TaskManagerBundle.php +++ b/src/TaskManagerBundle.php @@ -8,7 +8,6 @@ use Torr\TaskManager\DependencyInjection\AutoDetectFailureTransportsCompilerPass; use Torr\TaskManager\DependencyInjection\FindTaskClassesCompilerPass; use Torr\TaskManager\DependencyInjection\TaskManagerBundleExtension; -use Torr\TaskManager\Task\Task; final class TaskManagerBundle extends Bundle { @@ -28,9 +27,6 @@ public function build (ContainerBuilder $container) : void $container ->addCompilerPass(new AutoDetectFailureTransportsCompilerPass()) ->addCompilerPass(new FindTaskClassesCompilerPass()); - - $container->registerForAutoconfiguration(Task::class) - ->addTag("task-manager.task"); } /** From bdc2a319aa60558a77421c6b7bad7ddc2cee1302 Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Mon, 21 Sep 2026 17:04:06 +0200 Subject: [PATCH 4/5] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6b25a8..db6860f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ vNext * (impprovement) Display class name of wrapped Task when running `sf debug:scheduler` * (bug) Add proper support for fetching and validating Tasks that are configured via `#[AsMessage(…)]` attribute. +* (internal) Remove previously used Tag `task-manager.task`. 3.4.1 From 6f2e4dfc456798fc39d667d141542dbf6f630460 Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Mon, 21 Sep 2026 17:05:19 +0200 Subject: [PATCH 5/5] Fix deprecation in `TaskLog`'s `OrderBy` configuration --- CHANGELOG.md | 1 + src/Entity/TaskLog.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db6860f..6748fe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ vNext * (impprovement) Display class name of wrapped Task when running `sf debug:scheduler` * (bug) Add proper support for fetching and validating Tasks that are configured via `#[AsMessage(…)]` attribute. * (internal) Remove previously used Tag `task-manager.task`. +* (improvement) Fix deprecation in `TaskLog`'s `OrderBy` configuration. 3.4.1 diff --git a/src/Entity/TaskLog.php b/src/Entity/TaskLog.php index e446d43..1b7a31a 100644 --- a/src/Entity/TaskLog.php +++ b/src/Entity/TaskLog.php @@ -63,7 +63,7 @@ class TaskLog /** @var Collection */ #[ORM\OneToMany(mappedBy: "taskLog", targetEntity: TaskRun::class, cascade: ["remove"], orphanRemoval: true)] - #[ORM\OrderBy(["timeStarted" => "asc"])] + #[ORM\OrderBy(["timeStarted" => "ASC"])] public private(set) Collection $runs; /**