Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ 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
Expand Down
26 changes: 18 additions & 8 deletions src/DependencyInjection/FindTaskClassesCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,20 +23,29 @@ public function process (ContainerBuilder $container) : void
{
$taskClasses = [];

foreach ($container->findTaggedServiceIds("task-manager.task") as $taskServiceId => $config)
foreach ($container->getDefinitions() as $taskServiceId => $definition)
{
$definition = $container->getDefinition($taskServiceId);
$taskFQCN = $definition->getClass();

if (null !== $taskFQCN && str_starts_with($taskFQCN, "App\\"))
if (null === $taskFQCN || !str_starts_with($taskFQCN, "App\\"))
{
$taskClasses[] = $taskFQCN;
continue;
}

// 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);
$reflection = $container->getReflectionClass($taskFQCN, false);

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)
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/TaskLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TaskLog

/** @var Collection<int, TaskRun> */
#[ORM\OneToMany(mappedBy: "taskLog", targetEntity: TaskRun::class, cascade: ["remove"], orphanRemoval: true)]
#[ORM\OrderBy(["timeStarted" => "asc"])]
#[ORM\OrderBy(["timeStarted" => "ASC"])]
public private(set) Collection $runs;

/**
Expand Down
4 changes: 0 additions & 4 deletions src/TaskManagerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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");
}

/**
Expand Down
Loading