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
14 changes: 11 additions & 3 deletions src/Command/QueueTasksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Torr\TaskManager\Manager\TaskManager;
use Torr\TaskManager\Registry\TaskRegistry;
use Torr\TaskManager\Task\Task;
use Torr\TaskManager\Transport\TransportsHelper;

#[AsCommand("task-manager:queue")]
final class QueueTasksCommand extends Command
Expand All @@ -23,7 +22,6 @@ final class QueueTasksCommand extends Command
public function __construct (
private readonly TaskRegistry $taskRegistry,
private readonly TaskManager $taskManager,
private readonly TransportsHelper $receiverHelper,
private readonly HostingEnvironment $hostingEnvironment,
)
{
Expand Down Expand Up @@ -120,6 +118,16 @@ private function getTasksToQueue (InputInterface $input, TorrStyle $io) : array
}
}

$hasSyncTasks = array_any(
$flatTasks,
$this->taskManager->isUsingSyncTransport(...),
);

if ($hasSyncTasks)
{
$io->caution("For some tasks, this app is using sync transports: that means that these tasks are directly worked on.");
}

/** @var string[] $selectedOptions */
$selectedOptions = $io->choice(
"Which tasks should be queued?",
Expand Down Expand Up @@ -182,7 +190,7 @@ private function formatTaskLabel (Task $task) : string
);
}

if ($this->receiverHelper->usesSyncTransport($task))
if ($this->taskManager->isUsingSyncTransport($task))
{
$label = \sprintf("<fg=red>[sync]</> %s", $label);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Manager/TaskManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,16 @@ public function hasSyncTransport () : bool
{
return $this->transportsHelper->hasSyncTransport();
}

/**
* Returns whether the given task is using a sync transport.
*
* @param Envelope|Task|object $task
*
* @api
*/
public function isUsingSyncTransport (object $task) : bool
{
return $this->transportsHelper->isUsingSyncTransport($task);
}
}
22 changes: 1 addition & 21 deletions src/Transport/TransportsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
namespace Torr\TaskManager\Transport;

use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\Sender\SendersLocatorInterface;
use Symfony\Component\Messenger\Transport\Sync\SyncTransport;
use Symfony\Component\Messenger\Transport\TransportInterface;
use Torr\TaskManager\Config\BundleConfig;
use Torr\TaskManager\Exception\Transport\InvalidMessageTransportException;
use Torr\TaskManager\Task\Task;

/**
Expand Down Expand Up @@ -56,7 +54,7 @@ public function hasSyncTransport () : bool
/**
* @param Envelope|Task|object $message
*/
public function usesSyncTransport (object $message) : bool
public function isUsingSyncTransport (object $message) : bool
{
if (!$message instanceof Envelope)
{
Expand Down Expand Up @@ -101,24 +99,6 @@ public function getAllTransports () : array
return $transports;
}

public function getTransport (string $queueName) : TransportInterface
{
try
{
return $this->transports->get($queueName);
}
catch (ServiceNotFoundException $exception)
{
throw new InvalidMessageTransportException(
message: \sprintf(
"No transport found with queue name '%s'",
$queueName,
),
previous: $exception,
);
}
}

/**
* Returns all registered transport keys
*/
Expand Down
Loading