Skip to content

Commit

Permalink
Merge pull request #27 from michaelpetri/add-interval
Browse files Browse the repository at this point in the history
added interval to prevent polling filesystem
  • Loading branch information
michaelpetri committed May 12, 2023
2 parents 2083008 + c90ed24 commit 94d4ba5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Infrastructure/Transport/EventReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,24 @@
use Symfony\Component\Messenger\Transport\SetupableTransportInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

use function usleep;

final class EventReceiver implements TransportInterface, SetupableTransportInterface
{
/** @psalm-param positive-int $intervalInMilliSeconds */
public function __construct(
public readonly GitRepositoryInterface $repository
public readonly GitRepositoryInterface $repository,
public readonly int $intervalInMilliSeconds = 1
) {
}

public function get(): iterable
{
$needToSleep = true;

foreach ($this->repository->status()->toArray() as $change) {
$needToSleep = false;

switch ($change->index) {
case Status::ADDED:
case Status::MODIFIED:
Expand Down Expand Up @@ -88,6 +96,10 @@ public function get(): iterable
);
}
}

if ($needToSleep) {
usleep($this->intervalInMilliSeconds);
}
}

public function ack(Envelope $envelope): void
Expand Down

0 comments on commit 94d4ba5

Please sign in to comment.