Skip to content

Commit

Permalink
Remove obsolete job stamps + interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
apfelbox authored and keichinger committed May 16, 2024
1 parent 8f921fa commit 1001d59
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/Event/RegisterTasksEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class RegisterTasksEvent
*
* @throws DuplicateTaskRegisteredException
*/
public function registerTask (Task $task) : self
public function register (Task $task) : self
{
$definition = $task->getMetaData();
$key = $definition->getKey();
Expand Down
32 changes: 8 additions & 24 deletions src/Manager/TaskManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
use Symfony\Component\Messenger\Transport\TransportInterface;
use Torr\TaskManager\Config\BundleConfig;
use Torr\TaskManager\Exception\Manager\InvalidMessageTransportException;
use Torr\TaskManager\Message\UniqueMessageInterface;
use Torr\TaskManager\Stamp\UniqueJobStamp;
use Torr\TaskManager\Task\Task;

final class TaskManager
{
Expand All @@ -39,23 +38,12 @@ public function enqueue (
$jobId = $this->fetchJobIdFromMessage($message);
}

if (null === $jobId)
{
$this->messageBus->dispatch($message);
return true;
}

if (null !== $this->findQueuedMessageByUniqueJobId($jobId))
if (null !== $jobId && null !== $this->findQueuedMessageByUniqueJobId($jobId))
{
return false;
}

$envelope = $message instanceof Envelope
? $message
: new Envelope($message);

$envelope = $envelope->with(new UniqueJobStamp($jobId));
$this->messageBus->dispatch($envelope);
$this->messageBus->dispatch($message);
return true;

}
Expand All @@ -70,9 +58,7 @@ private function findQueuedMessageByUniqueJobId (string $jobId) : ?Envelope
{
foreach ($this->fetchTasksInQueue($queueName) as $envelope)
{
$stamp = $envelope->last(UniqueJobStamp::class);

if (null !== $stamp && $stamp->jobId === $jobId)
if ($this->fetchJobIdFromMessage($envelope) === $jobId)
{
return $envelope;
}
Expand Down Expand Up @@ -138,6 +124,7 @@ public function getAllQueues () : array
);
}


/**
*
*/
Expand All @@ -149,11 +136,8 @@ private function fetchJobIdFromMessage (object $message) : ?string
$message = $message->getMessage();
}

if ($message instanceof UniqueMessageInterface)
{
return $message->getJobId();
}

return null;
return $message instanceof Task
? $message->getMetaData()->uniqueTaskId
: null;
}
}
15 changes: 0 additions & 15 deletions src/Message/UniqueMessageInterface.php

This file was deleted.

12 changes: 0 additions & 12 deletions src/Stamp/UniqueJobStamp.php

This file was deleted.

0 comments on commit 1001d59

Please sign in to comment.