Skip to content

Symfony 6 and PHP 8.1+ #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- Update dependencies and code to work with Symfony ^6.0 and PHP ^8.1.

### Breaking changes
- PHP >= 8.1
- Symfony ^6.0

## [5.1.0] - 2023-03-14
### Fixed
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ The bundle piggybacks off of the `php-amqplib/rabbitmq-bundle` bundle.

## Setup & Dependencies

* PHP `>=7.0`
* https://packagist.org/packages/symfony/symfony `^3.4|^4.0`
* https://packagist.org/packages/doctrine/orm `~2.5`
* https://packagist.org/packages/monolog/monolog `~1.11`
* https://packagist.org/packages/ramsey/uuid `~3.4`
* https://packagist.org/packages/php-amqplib/rabbitmq-bundle `~1.6`
* PHP `>=8.1`
* https://packagist.org/packages/symfony/symfony `^6.0`
* https://packagist.org/packages/doctrine/orm `~2.14`
* https://packagist.org/packages/monolog/monolog `~2.8`
* https://packagist.org/packages/ramsey/uuid `~4.7`
* https://packagist.org/packages/php-amqplib/rabbitmq-bundle `~2.11`

We assume that you are familiar with the `php-amqplib/rabbitmq-bundle` configuration and setup.

Expand Down
40 changes: 22 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,33 @@
},

"require": {
"php": ">=7.0",
"php": ">=8.1",

"symfony/config": "^3.4 || ^4.0",
"symfony/console": "^3.4 || ^4.0",
"symfony/dependency-injection": "^3.4 || ^4.0",
"symfony/expression-language": "^3.4 || ^4.0",
"symfony/filesystem": "^3.4 || ^4.0",
"symfony/http-foundation": "^3.4 || ^4.0",
"symfony/http-kernel": "^3.4 || ^4.0",
"symfony/validator": "^3.4 || ^4.0",
"symfony/config": "^6.0",
"symfony/console": "^6.0",
"symfony/dependency-injection": "^6.0",
"symfony/expression-language": "^6.0",
"symfony/filesystem": "^6.0",
"symfony/http-foundation": "^6.0",
"symfony/http-kernel": "^6.0",
"symfony/validator": "^6.0",

"doctrine/cache": "^1.6",
"doctrine/doctrine-bundle": "~1.4",
"doctrine/orm": "~2.5",
"doctrine/cache": "^2.0",
"doctrine/doctrine-bundle": "^2.8",
"doctrine/orm": "^2.14",

"monolog/monolog": "~1.11",
"monolog/monolog": "^2.8",

"php-amqplib/rabbitmq-bundle": "^1.13.0",
"php-amqplib/rabbitmq-bundle": "^2.11",

"ramsey/uuid": "~3.4",
"php-http/guzzle6-adapter": "^1.1",
"richardfullmer/rabbitmq-management-api": "^2.0",
"ramsey/uuid": "^4.7",
"php-http/guzzle7-adapter": "^1.0",
"andrewmy/rabbitmq-management-api": "^2.1",
"psr/log": "^1.0"
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}

}
15 changes: 7 additions & 8 deletions src/Printed/Bundle/Queue/Command/EnsureVhostExistsCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Printed\Bundle\Queue\Command;

use Printed\Bundle\Queue\Service\RabbitMqVhostExistenceEnsurer;
Expand All @@ -13,21 +15,16 @@
*/
class EnsureVhostExistsCommand extends Command
{
/** @var RabbitMqVhostExistenceEnsurer */
private $rabbitMqVhostExistenceEnsurer;

public function __construct(
RabbitMqVhostExistenceEnsurer $rabbitMqVhostExistenceEnsurer
private readonly RabbitMqVhostExistenceEnsurer $rabbitMqVhostExistenceEnsurer,
) {
parent::__construct();

$this->rabbitMqVhostExistenceEnsurer = $rabbitMqVhostExistenceEnsurer;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('queue:ensure-vhost-exists');
$this->setDescription("Ensures, that a rabbitmq's vhost exists, and that rabbitmq's user can manage it");
Expand All @@ -36,13 +33,15 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
if ($output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) {
$output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
}

$this->rabbitMqVhostExistenceEnsurer->ensure();

return static::SUCCESS;
}

}
17 changes: 8 additions & 9 deletions src/Printed/Bundle/Queue/Command/MaintenanceDownCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Printed\Bundle\Queue\Command;

use Printed\Bundle\Queue\Service\QueueMaintenance;
Expand All @@ -12,20 +14,15 @@
*/
class MaintenanceDownCommand extends Command
{
/** @var QueueMaintenance */
private $queueMaintenance;

public function __construct(QueueMaintenance $queueMaintenance)
public function __construct(private readonly QueueMaintenance $queueMaintenance)
{
parent::__construct();

$this->queueMaintenance = $queueMaintenance;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('queue:maintenance:down');
$this->setDescription('Disable the maintenance mode for the queue');
Expand All @@ -35,10 +32,12 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('<info>Disabling maintenance mode</info>');

$this->queueMaintenance->disable();

return static::SUCCESS;
}
}
15 changes: 7 additions & 8 deletions src/Printed/Bundle/Queue/Command/MaintenanceUpCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Printed\Bundle\Queue\Command;

use Printed\Bundle\Queue\Service\QueueMaintenance;
Expand All @@ -12,20 +14,15 @@
*/
class MaintenanceUpCommand extends Command
{
/** @var QueueMaintenance */
private $queueMaintenance;

public function __construct(QueueMaintenance $queueMaintenance)
public function __construct(private readonly QueueMaintenance $queueMaintenance)
{
parent::__construct();

$this->queueMaintenance = $queueMaintenance;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('queue:maintenance:up');
$this->setDescription('Puts the queue in to maintenance mode');
Expand All @@ -35,10 +32,12 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('<info>Enabling maintenance mode</info>');

$this->queueMaintenance->enable();

return static::SUCCESS;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Printed\Bundle\Queue\Command;

use Doctrine\DBAL\Connection;
Expand All @@ -17,26 +19,17 @@
*/
class MaintenanceWaitForRunningCommand extends Command
{
/** @var QueueMaintenance */
private $queueMaintenance;

/** @var Connection */
private $dbalConnection;

public function __construct(
QueueMaintenance $queueMaintenance,
Connection $dbalConnection
private readonly QueueMaintenance $queueMaintenance,
private readonly Connection $dbalConnection,
) {
parent::__construct();

$this->queueMaintenance = $queueMaintenance;
$this->dbalConnection = $dbalConnection;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('queue:maintenance:wait');
$this->setDescription('Wait for running tasks to complete and exit');
Expand All @@ -49,7 +42,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('<info>Monitoring running tasks</info>');

Expand All @@ -65,28 +58,30 @@ public function execute(InputInterface $input, OutputInterface $output)
$dbal = $this->dbalConnection;

if (!$this->doesDatabaseExist($dbal)) {
$output->writeln("<error>The database doesn't exist. This is expected, if the bundle is used for the first time. Otherwise it's a critical error you should investigate.</error>");
return;
$output->writeln("<comment>The database doesn't exist. This is expected, if the bundle is used for the first time. Otherwise, it's a critical error you should investigate.</comment>");

return static::SUCCESS;
}

/*
* Exit immediately if the queue tasks db table is not in the database. Assume no workers
* are running.
*/
if (!in_array('queue_task', $dbal->getSchemaManager()->listTableNames())) {
$output->writeln("<error>Couldn't find the queue tasks table in the database. This is expected, if the bundle is used for the first time. Otherwise it's a critical error you should investigate.</error>");
return;
if (!in_array('queue_task', $dbal->createSchemaManager()->listTableNames())) {
$output->writeln("<comment>Couldn't find the queue tasks table in the database. This is expected, if the bundle is used for the first time. Otherwise, it's a critical error you should investigate.</comment>");

return static::SUCCESS;
}

// Get the refresh time, this is 3 by default.
$refresh = (integer) $input->getOption('refresh');
$refresh = (int) $input->getOption('refresh');

$table = new Table($output);
$table->setHeaders(['Queue', 'Tasks']);

while (true) {
// Find all tasks with running status.
$tasks = $dbal->fetchAll(
$tasks = $dbal->fetchAllAssociative(
'SELECT id, queue_name FROM queue_task WHERE status = :status_running',
[ 'status_running' => QueueTaskStatus::RUNNING ]
);
Expand All @@ -95,7 +90,8 @@ public function execute(InputInterface $input, OutputInterface $output)
// If there are none we can exit the command.
if ($count === 0) {
$output->writeln(sprintf('<info>There are no tasks in running state!</info>'));
return;

return static::SUCCESS;
}

$table->setRows([]);
Expand Down Expand Up @@ -162,7 +158,7 @@ private function doesDatabaseExist(Connection $connection): bool

$tmpConnection = DriverManager::getConnection($params);

$doesDatabaseExist = in_array($name, $tmpConnection->getSchemaManager()->listDatabases());
$doesDatabaseExist = in_array($name, $tmpConnection->createSchemaManager()->listDatabases());

$tmpConnection->close();

Expand Down
35 changes: 11 additions & 24 deletions src/Printed/Bundle/Queue/Command/RequeueTaskCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Printed\Bundle\Queue\Command;

use Printed\Bundle\Queue\Helper\QueueTaskHelper;
Expand All @@ -17,39 +19,22 @@
*/
class RequeueTaskCommand extends Command
{
/** @var LoggerInterface */
private $logger;

/** @var QueueTaskDispatcher */
private $queueTaskDispatcher;

/** @var QueueTaskHelper */
private $queueTaskHelper;

/** @var QueueTaskRepository */
private $queueTaskRepository;

public function __construct(
LoggerInterface $logger,
QueueTaskDispatcher $queueTaskDispatcher,
QueueTaskHelper $queueTaskHelper,
QueueTaskRepository $queueTaskRepository
private readonly LoggerInterface $logger,
private readonly QueueTaskDispatcher $queueTaskDispatcher,
private readonly QueueTaskHelper $queueTaskHelper,
private readonly QueueTaskRepository $queueTaskRepository,
) {
parent::__construct();

$this->logger = $logger;
$this->queueTaskDispatcher = $queueTaskDispatcher;
$this->queueTaskHelper = $queueTaskHelper;
$this->queueTaskRepository = $queueTaskRepository;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('queue:requeue-task');
$this->setDescription("Requeues a task. Should be used with great care (preferably never)");
$this->setDescription("Re-queues a task. Should be used with great care (preferably never)");
$this->setHelp('This command allows to perform dangerous stuff and is mostly useful only for debugging.');

$this->addArgument('queue-task-id', InputArgument::REQUIRED, 'Queue task to requeue');
Expand All @@ -58,7 +43,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
if ($output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) {
$output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
Expand All @@ -77,5 +62,7 @@ public function execute(InputInterface $input, OutputInterface $output)
$newTask = $this->queueTaskDispatcher->dispatch($this->queueTaskHelper->getPayload($task));

$this->logger->info("Successfully requeued task. New task id: `{$newTask->getId()}`");

return static::SUCCESS;
}
}
Loading