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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.3.1
=====

* (bug) Properly handle `DispatchAfterRunTask`.
* (improvement) Add `task_manager_internals` transport for internal messages.


2.3.0
=====

Expand Down
62 changes: 62 additions & 0 deletions src/DependencyInjection/TaskManagerBundleExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php declare(strict_types=1);

namespace Torr\TaskManager\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Torr\BundleHelpers\Bundle\BundleExtension;
use Torr\TaskManager\Config\BundleConfig;
use Torr\TaskManager\Log\LogCleaner;
use Torr\TaskManager\Task\DispatchAfterRunTask\DispatchAfterRunTask;

/**
* @final
*/
class TaskManagerBundleExtension extends BundleExtension implements PrependExtensionInterface
{
/**
*
*/
#[\Override]
public function load (array $configs, ContainerBuilder $container) : void
{
parent::load($configs, $container);

$config = $this->processConfiguration(new TaskManagerBundleConfiguration(), $configs);

$container->getDefinition(BundleConfig::class)
->setArgument('$sortedQueues', $config["queues"]);

// if the new value was customized, use it. Otherwise keep using
// the old value. If none is set, they use the same default, so everything
// is fine.
$logTtl = 28 !== $config["log"]["ttl"]
? $config["log"]["ttl"]
: $config["log_ttl"];

$container->getDefinition(LogCleaner::class)
->setArgument('$logTtlInDays', $logTtl)
->setArgument('$logMaxEntries', $config["log"]["max_entries"]);
}

/**
*
*/
#[\Override]
public function prepend (ContainerBuilder $container) : void
{
$container->prependExtensionConfig("framework", [
// We only register the sync task, so that the own tasks are worked on right away
"messenger" => [
"transports" => [
"task_manager_internals" => [
"dsn" => 'sync://',
],
],
"routing" => [
DispatchAfterRunTask::class => "task_manager_internals",
],
],
]);
}
}
2 changes: 2 additions & 0 deletions src/Task/DispatchAfterRunTask/DispatchAfterRunTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Torr\TaskManager\Task\DispatchAfterRunTask;

use Symfony\Component\Messenger\Attribute\AsMessage;
use Torr\TaskManager\Task\Task;
use Torr\TaskManager\Task\TaskMetaData;

Expand All @@ -11,6 +12,7 @@
* This task is supposed to be worked on synchronously, as it is pretty lightweight and only
* redispatches the given task.
*/
#[AsMessage(transport: "task_manager_internals")]
readonly class DispatchAfterRunTask extends Task
{
public function __construct (
Expand Down
26 changes: 2 additions & 24 deletions src/TaskManagerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Torr\BundleHelpers\Bundle\ConfigurableBundleExtension;
use Torr\TaskManager\Config\BundleConfig;
use Torr\TaskManager\DependencyInjection\AutoDetectFailureTransportsCompilerPass;
use Torr\TaskManager\DependencyInjection\FindTaskClassesCompilerPass;
use Torr\TaskManager\DependencyInjection\TaskManagerBundleConfiguration;
use Torr\TaskManager\Log\LogCleaner;
use Torr\TaskManager\DependencyInjection\TaskManagerBundleExtension;
use Torr\TaskManager\Task\Task;

final class TaskManagerBundle extends Bundle
Expand All @@ -20,26 +17,7 @@ final class TaskManagerBundle extends Bundle
*/
public function getContainerExtension () : ExtensionInterface
{
return new ConfigurableBundleExtension(
$this,
new TaskManagerBundleConfiguration(),
static function (array $config, ContainerBuilder $container) : void
{
$container->getDefinition(BundleConfig::class)
->setArgument('$sortedQueues', $config["queues"]);

// if the new value was customized, use it. Otherwise keep using
// the old value. If none is set, they use the same default, so everything
// is fine.
$logTtl = 28 !== $config["log"]["ttl"]
? $config["log"]["ttl"]
: $config["log_ttl"];

$container->getDefinition(LogCleaner::class)
->setArgument('$logTtlInDays', $logTtl)
->setArgument('$logMaxEntries', $config["log"]["max_entries"]);
},
);
return new TaskManagerBundleExtension($this, "task_manager");
}

/**
Expand Down