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
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"ext-pcntl": "*",
"b2pweb/bdf-dsn": "~1.0",
"b2pweb/bdf-instantiator": "~1.0",
"symfony/console": "~5.4|~6.0|~7.0",
"symfony/messenger": "~5.4|~6.0|~7.0"
"symfony/console": "~5.4|~6.0|~7.0|~8.0",
"symfony/messenger": "~5.4|~6.0|~7.0|~8.0"
},
"require-dev": {
"b2pweb/bdf-serializer": "~1.0",
"doctrine/dbal": "~2.5|~3.0",
"doctrine/dbal": "~2.5|~3.0|~4.0",
"ramsey/uuid": "~3.0|~4.0",
"enqueue/enqueue": "~0.9",
"enqueue/fs": "~0.9",
Expand All @@ -41,9 +41,9 @@
"php-amqplib/php-amqplib": "~3.0",
"phpbench/phpbench": "~0.0|~1.0",
"phpunit/phpunit": "~9.6",
"symfony/error-handler": "~5.4|~6.0|~7.0",
"symfony/phpunit-bridge": "~5.4|~6.0|~7.0",
"symfony/var-dumper": "~5.4|~6.0|~7.0",
"symfony/error-handler": "~5.4|~6.0|~7.0|~8.0",
"symfony/phpunit-bridge": "~5.4|~6.0|~7.0|~8.0",
"symfony/var-dumper": "~5.4|~6.0|~7.0|~8.0",
"vimeo/psalm": "~5.22 | ~6.0",
"predis/predis": "~1.1.0",
"friendsofphp/php-cs-fixer": "^3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Doctrine/DoctrineConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function connection(): Connection
if ($this->connection === null) {
try {
$this->connection = DriverManager::getConnection($this->config);
$this->connection->connect();
$this->connection->executeQuery('SELECT 1');
} catch (Exception $e) {
throw new ConnectionFailedException($e->getMessage(), $e->getCode(), $e);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Connection/Doctrine/DoctrineQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
use Bdf\Queue\Message\Message;
use Bdf\Queue\Message\QueuedMessage;
use DateTime;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Types\Types;
use Ramsey\Uuid\Uuid;

Expand Down Expand Up @@ -105,11 +107,12 @@ public function pop(string $queue, int $duration = ConnectionDriverInterface::DU
public function reserve(int $number, string $queue, int $duration = ConnectionDriverInterface::DURATION): array
{
$doctrine = $this->connection->connection();
$forUpdate = $doctrine->getDatabasePlatform() instanceof SqlitePlatform ? '' : 'FOR UPDATE';

// The query builder of Doctrine does not manage the lock for update.
$sql = 'SELECT * FROM '.$doctrine->quoteIdentifier($this->connection->table()).'
WHERE queue = :queue AND reserved = :reserved AND available_at <= :available_at
ORDER BY available_at, created_at LIMIT '.((int)$number).' '.$doctrine->getDatabasePlatform()->getForUpdateSql();
ORDER BY available_at, created_at LIMIT '.((int)$number).' '.$forUpdate;

$task = function () use ($sql, $queue, $doctrine) {
$dbJobs = $doctrine->executeQuery(
Expand Down Expand Up @@ -142,7 +145,7 @@ public function reserve(int $number, string $queue, int $duration = ConnectionDr
->andWhere('id IN (:ids)')
->setParameter('reserved', true, Types::BOOLEAN)
->setParameter('reserved_at', new DateTime(), Types::DATETIME_MUTABLE)
->setParameter('ids', $ids, Connection::PARAM_STR_ARRAY);
->setParameter('ids', $ids, ArrayParameterType::STRING);

// Doctrine 3 compatibility
if (method_exists($updateQuery, 'executeStatement')) {
Expand Down
4 changes: 3 additions & 1 deletion tests/Console/Command/BindCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;

use function method_exists;

/**
*
*/
Expand Down Expand Up @@ -75,7 +77,7 @@ public function test_complete(array $input, array $expectedSuggestions)

$command = new BindCommand($factory);
$application = new Application();
$application->add($command);
method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command);

$tester = new CommandCompletionTester($application->get('queue:bind'));
$suggestions = $tester->complete($input);
Expand Down
6 changes: 4 additions & 2 deletions tests/Console/Command/ConsumeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;

use function method_exists;

/**
* @group Bdf_Queue
* @group Bdf_Queue_Console
Expand Down Expand Up @@ -393,7 +395,7 @@ public function test_complete(array $input, array $expectedSuggestions)

$command = new ConsumeCommand($this->manager, $this->container->get(ReceiverLoader::class));
$application = new Application();
$application->add($command);
method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command);

$tester = new CommandCompletionTester($application->get('queue:consume'));
$suggestions = $tester->complete($input);
Expand Down Expand Up @@ -467,4 +469,4 @@ public function wait()
{
sleep(self::$sleep);
}
}
}
6 changes: 4 additions & 2 deletions tests/Console/Command/InfoCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;

use function method_exists;

/**
* @group Bdf_Queue
* @group Bdf_Queue_Console
Expand Down Expand Up @@ -118,7 +120,7 @@ public function test_complete(array $input, array $expectedSuggestions)

$command = new InfoCommand($this->container->get(ConnectionDriverFactoryInterface::class));
$application = new Application();
$application->add($command);
method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command);

$tester = new CommandCompletionTester($application->get('queue:info'));
$suggestions = $tester->complete($input);
Expand Down Expand Up @@ -165,4 +167,4 @@ public function test_json_format()

$this->assertSame($expected, json_decode($tester->getDisplay(), true));
}
}
}
4 changes: 3 additions & 1 deletion tests/Console/Command/ProduceCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;

use function method_exists;

/**
* @group Bdf_Queue
* @group Bdf_Queue_Console
Expand Down Expand Up @@ -156,7 +158,7 @@ public function test_complete(array $input, array $expectedSuggestions)

$command = new ProduceCommand($this->manager);
$application = new Application();
$application->add($command);
method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command);

$tester = new CommandCompletionTester($application->get('queue:produce'));
$suggestions = $tester->complete($input);
Expand Down
4 changes: 3 additions & 1 deletion tests/Console/Command/SetupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;

use function method_exists;

/**
*
*/
Expand Down Expand Up @@ -162,7 +164,7 @@ public function test_complete(array $input, array $expectedSuggestions)

$command = new SetupCommand($this->manager);
$application = new Application();
$application->add($command);
method_exists($application, 'addCommand') ? $application->addCommand($command) : $application->add($command);

$tester = new CommandCompletionTester($application->get('queue:setup'));
$suggestions = $tester->complete($input);
Expand Down
Loading