Skip to content

Commit

Permalink
Add warning to show that a sync queue is in use
Browse files Browse the repository at this point in the history
  • Loading branch information
apfelbox committed May 14, 2024
1 parent d6b9a71 commit 6f4aa1d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Command/QueueTasksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Torr\Cli\Console\Style\TorrStyle;
use Torr\TaskManager\Exception\Registry\UnknownTaskKeyException;
use Torr\TaskManager\Manager\TaskManager;
use Torr\TaskManager\Receiver\ReceiverHelper;
use Torr\TaskManager\Registry\Data\Task;
use Torr\TaskManager\Registry\TaskRegistry;

Expand All @@ -21,6 +22,7 @@ final class QueueTasksCommand extends Command
public function __construct (
private readonly TaskRegistry $taskRegistry,
private readonly TaskManager $taskManager,
private readonly ReceiverHelper $receiverHelper,
)
{
parent::__construct();
Expand All @@ -42,7 +44,12 @@ protected function configure () : void
protected function execute (InputInterface $input, OutputInterface $output) : int
{
$io = new TorrStyle($input, $output);
$io->title("Task Manager: Queue Task");
$io->title("Task Manager: Queue Task");

if ($this->receiverHelper->hasSyncTransport())
{
$io->caution("The app is using sync transports: that means that registered tasks are directly worked on.");
}

try
{
Expand Down
37 changes: 37 additions & 0 deletions src/Receiver/ReceiverHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php declare(strict_types=1);

namespace Torr\TaskManager\Receiver;

use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\Messenger\Transport\Sync\SyncTransport;
use Symfony\Component\Messenger\Transport\TransportInterface;

/**
* @internal
*/
final class ReceiverHelper
{
/**
*/
public function __construct (
/** @var iterable<TransportInterface> */
#[TaggedIterator("messenger.receiver")]
private readonly iterable $transports,
) {}

/**
* Returns whether the app uses sync transports
*/
public function hasSyncTransport () : bool
{
foreach ($this->transports as $transport)
{
if ($transport instanceof SyncTransport)
{
return true;
}
}

return false;
}
}

0 comments on commit 6f4aa1d

Please sign in to comment.