From d86c1fa0f8a057bbbc510bb09156a248f847e365 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Fri, 9 Apr 2021 18:36:23 +0200 Subject: [PATCH] Ability to run update on separate worker process --- api/.env | 4 + api/bin/docker-entrypoint.sh | 3 + api/composer.json | 17 +- api/composer.lock | 486 +++++++++++++++++- api/config/bundles.php | 1 + api/config/packages/messenger.yaml | 13 + api/dev.Dockerfile | 1 - api/src/Command/UpdateCommand.php | 34 +- api/src/Message/UpdateDataMessage.php | 7 + .../UpdateDataMessageHandler.php | 34 ++ api/src/Output/LoggerOutput.php | 30 ++ api/src/Service/DataUpdater.php | 19 +- api/symfony.lock | 33 ++ 13 files changed, 638 insertions(+), 44 deletions(-) create mode 100644 api/bin/docker-entrypoint.sh create mode 100644 api/config/packages/messenger.yaml create mode 100644 api/src/Message/UpdateDataMessage.php create mode 100644 api/src/MessageHandler/UpdateDataMessageHandler.php create mode 100644 api/src/Output/LoggerOutput.php diff --git a/api/.env b/api/.env index 8e84d99..c2d60f7 100644 --- a/api/.env +++ b/api/.env @@ -16,3 +16,7 @@ APP_SECRET=494a9d1f8cc383f16075f4d5e54ae1a2 DATABASE_URL="sqlite:///%kernel.project_dir%/var/app.db" # DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7" ###< doctrine/doctrine-bundle ### + +###> symfony/messenger ### +MESSENGER_TRANSPORT_DSN="doctrine://default" +###< symfony/messenger ### diff --git a/api/bin/docker-entrypoint.sh b/api/bin/docker-entrypoint.sh new file mode 100644 index 0000000..214eb4c --- /dev/null +++ b/api/bin/docker-entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec "$@" diff --git a/api/composer.json b/api/composer.json index 3ea61f5..18f4cc4 100644 --- a/api/composer.json +++ b/api/composer.json @@ -4,12 +4,13 @@ "type": "project", "license": "MIT with Commons Clause", "require": { - "php": "^7.1.3", + "php": "^7.4", "ext-ctype": "*", "ext-iconv": "*", "ext-json": "*", "baldinof/roadrunner-bundle": "^1.3", "cerbero/json-objects": "^1.1", + "illuminate/collections": "^8.35", "jms/serializer-bundle": "^3.5", "kadet/functional": "dev-master", "nelmio/api-doc-bundle": "^3.5", @@ -19,15 +20,18 @@ "spiral/roadrunner": "^1.8", "symfony/asset": "^5.2", "symfony/console": "^5.2", - "symfony/dotenv": "^5.2", + "symfony/doctrine-messenger": "5.2.*", "symfony/flex": "^1.1", "symfony/framework-bundle": "^5.2", + "symfony/messenger": "5.2.*", "symfony/monolog-bundle": "^3.3", "symfony/orm-pack": "^1.0", "symfony/profiler-pack": "^1.0", "symfony/twig-bundle": "^5.2", "symfony/yaml": "^5.2", - "illuminate/collections": "^8.35" + "symfony/dotenv": "5.2.*", + "symfony/amqp-messenger": "5.2.*", + "symfony/redis-messenger": "5.2.*" }, "config": { "preferred-install": { @@ -36,7 +40,7 @@ "sort-packages": true, "secure-http": false, "platform": { - "php": "7.3.12" + "php": "7.4.15" } }, "autoload": { @@ -86,5 +90,8 @@ "type": "vcs", "url": "https://git.kadet.net/kadet/functional-php.git" } - ] + ], + "require-dev": { + "symfony/maker-bundle": "^1.30" + } } diff --git a/api/composer.lock b/api/composer.lock index 8562678..a8bc93c 100644 --- a/api/composer.lock +++ b/api/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4c087fa5970989805008ea426fdd2221", + "content-hash": "3703fdd98d8c7ed6539721bde9035bba", "packages": [ { "name": "baldinof/roadrunner-bundle", @@ -3693,6 +3693,75 @@ }, "time": "2021-01-14T16:04:43+00:00" }, + { + "name": "symfony/amqp-messenger", + "version": "v5.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/amqp-messenger.git", + "reference": "cf309a35ed08caa77886ee6a352b8491c7681424" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/amqp-messenger/zipball/cf309a35ed08caa77886ee6a352b8491c7681424", + "reference": "cf309a35ed08caa77886ee6a352b8491c7681424", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1", + "symfony/messenger": "^5.1" + }, + "require-dev": { + "symfony/event-dispatcher": "^4.4|^5.0", + "symfony/process": "^4.4|^5.0", + "symfony/property-access": "^4.4|^5.0", + "symfony/serializer": "^4.4|^5.0" + }, + "type": "symfony-bridge", + "autoload": { + "psr-4": { + "Symfony\\Component\\Messenger\\Bridge\\Amqp\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony AMQP extension Messenger Bridge", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/amqp-messenger/tree/v5.2.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-27T11:19:04+00:00" + }, { "name": "symfony/asset", "version": "v5.2.4", @@ -4380,30 +4449,38 @@ "time": "2021-03-10T22:10:15+00:00" }, { - "name": "symfony/dotenv", - "version": "v5.2.4", + "name": "symfony/doctrine-messenger", + "version": "v5.2.5", "source": { "type": "git", - "url": "https://github.com/symfony/dotenv.git", - "reference": "783f12027c6b40ab0e93d6136d9f642d1d67cd6b" + "url": "https://github.com/symfony/doctrine-messenger.git", + "reference": "10136ef0e31ca9839254bd909ef42421b61bc118" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dotenv/zipball/783f12027c6b40ab0e93d6136d9f642d1d67cd6b", - "reference": "783f12027c6b40ab0e93d6136d9f642d1d67cd6b", + "url": "https://api.github.com/repos/symfony/doctrine-messenger/zipball/10136ef0e31ca9839254bd909ef42421b61bc118", + "reference": "10136ef0e31ca9839254bd909ef42421b61bc118", "shasum": "" }, "require": { "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1" + "symfony/messenger": "^5.1", + "symfony/service-contracts": "^1.1|^2" + }, + "conflict": { + "doctrine/dbal": "<2.10", + "doctrine/persistence": "<1.3" }, "require-dev": { - "symfony/process": "^4.4|^5.0" + "doctrine/dbal": "^2.10|^3.0", + "doctrine/persistence": "^1.3|^2", + "symfony/property-access": "^4.4|^5.0", + "symfony/serializer": "^4.4|^5.0" }, - "type": "library", + "type": "symfony-bridge", "autoload": { "psr-4": { - "Symfony\\Component\\Dotenv\\": "" + "Symfony\\Component\\Messenger\\Bridge\\Doctrine\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -4423,15 +4500,10 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Registers environment variables from a .env file", + "description": "Symfony Doctrine Messenger Bridge", "homepage": "https://symfony.com", - "keywords": [ - "dotenv", - "env", - "environment" - ], "support": { - "source": "https://github.com/symfony/dotenv/tree/v5.2.4" + "source": "https://github.com/symfony/doctrine-messenger/tree/v5.2.5" }, "funding": [ { @@ -4447,7 +4519,7 @@ "type": "tidelift" } ], - "time": "2021-01-27T10:01:46+00:00" + "time": "2021-03-05T12:14:19+00:00" }, { "name": "symfony/error-handler", @@ -5286,6 +5358,94 @@ ], "time": "2021-03-29T05:16:58+00:00" }, + { + "name": "symfony/messenger", + "version": "v5.2.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/messenger.git", + "reference": "bc012fde3b96cfa3adf22f4d8a2e17860dc24a65" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/messenger/zipball/bc012fde3b96cfa3adf22f4d8a2e17860dc24a65", + "reference": "bc012fde3b96cfa3adf22f4d8a2e17860dc24a65", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "psr/log": "~1.0", + "symfony/amqp-messenger": "^5.1", + "symfony/deprecation-contracts": "^2.1", + "symfony/doctrine-messenger": "^5.1", + "symfony/polyfill-php80": "^1.15", + "symfony/redis-messenger": "^5.1" + }, + "conflict": { + "symfony/event-dispatcher": "<4.4", + "symfony/framework-bundle": "<4.4", + "symfony/http-kernel": "<4.4" + }, + "require-dev": { + "psr/cache": "^1.0|^2.0|^3.0", + "symfony/console": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/event-dispatcher": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0", + "symfony/process": "^4.4|^5.0", + "symfony/property-access": "^4.4|^5.0", + "symfony/serializer": "^4.4|^5.0", + "symfony/service-contracts": "^1.1|^2", + "symfony/stopwatch": "^4.4|^5.0", + "symfony/validator": "^4.4|^5.0" + }, + "suggest": { + "enqueue/messenger-adapter": "For using the php-enqueue library as a transport." + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Messenger\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Samuel Roze", + "email": "samuel.roze@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Helps applications send and receive messages to/from other applications or via message queues", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/messenger/tree/v5.2.5" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-03-06T07:59:01+00:00" + }, { "name": "symfony/monolog-bridge", "version": "v5.2.5", @@ -6194,6 +6354,73 @@ ], "time": "2021-02-17T10:35:25+00:00" }, + { + "name": "symfony/redis-messenger", + "version": "v5.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/redis-messenger.git", + "reference": "7e68914bf35cda948ee4d9081b8eaed9fd783fe5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/redis-messenger/zipball/7e68914bf35cda948ee4d9081b8eaed9fd783fe5", + "reference": "7e68914bf35cda948ee4d9081b8eaed9fd783fe5", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1", + "symfony/messenger": "^5.1" + }, + "require-dev": { + "symfony/property-access": "^4.4|^5.0", + "symfony/serializer": "^4.4|^5.0" + }, + "type": "symfony-bridge", + "autoload": { + "psr-4": { + "Symfony\\Component\\Messenger\\Bridge\\Redis\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Redis extension Messenger Bridge", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/redis-messenger/tree/v5.2.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-27T11:24:50+00:00" + }, { "name": "symfony/routing", "version": "v5.2.6", @@ -7525,7 +7752,222 @@ "time": "2020-11-29T21:40:13+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "nikic/php-parser", + "version": "v4.10.4", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/c6d052fc58cb876152f89f532b95a8d7907e7f0e", + "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.4" + }, + "time": "2020-12-20T10:01:03+00:00" + }, + { + "name": "symfony/dotenv", + "version": "v5.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/dotenv.git", + "reference": "783f12027c6b40ab0e93d6136d9f642d1d67cd6b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dotenv/zipball/783f12027c6b40ab0e93d6136d9f642d1d67cd6b", + "reference": "783f12027c6b40ab0e93d6136d9f642d1d67cd6b", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1" + }, + "require-dev": { + "symfony/process": "^4.4|^5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Dotenv\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Registers environment variables from a .env file", + "homepage": "https://symfony.com", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "support": { + "source": "https://github.com/symfony/dotenv/tree/v5.2.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-27T10:01:46+00:00" + }, + { + "name": "symfony/maker-bundle", + "version": "v1.30.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/maker-bundle.git", + "reference": "a395a85aa4ded6c1fa3da118d60329b64b6c2acd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/maker-bundle/zipball/a395a85aa4ded6c1fa3da118d60329b64b6c2acd", + "reference": "a395a85aa4ded6c1fa3da118d60329b64b6c2acd", + "shasum": "" + }, + "require": { + "doctrine/inflector": "^1.2|^2.0", + "nikic/php-parser": "^4.0", + "php": ">=7.1.3", + "symfony/config": "^4.0|^5.0", + "symfony/console": "^4.0|^5.0", + "symfony/dependency-injection": "^4.0|^5.0", + "symfony/deprecation-contracts": "^2.2", + "symfony/filesystem": "^4.0|^5.0", + "symfony/finder": "^4.0|^5.0", + "symfony/framework-bundle": "^4.0|^5.0", + "symfony/http-kernel": "^4.0|^5.0" + }, + "require-dev": { + "composer/semver": "^3.0@dev", + "doctrine/doctrine-bundle": "^1.8|^2.0", + "doctrine/orm": "^2.3", + "friendsofphp/php-cs-fixer": "^2.8", + "friendsoftwig/twigcs": "^4.1.0|^5.0.0", + "symfony/http-client": "^4.3|^5.0", + "symfony/phpunit-bridge": "^4.3|^5.0", + "symfony/process": "^4.0|^5.0", + "symfony/security-core": "^4.0|^5.0", + "symfony/yaml": "^4.0|^5.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-main": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bundle\\MakerBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.", + "homepage": "https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html", + "keywords": [ + "code generator", + "generator", + "scaffold", + "scaffolding" + ], + "support": { + "issues": "https://github.com/symfony/maker-bundle/issues", + "source": "https://github.com/symfony/maker-bundle/tree/v1.30.2" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-03-23T13:53:38+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": { @@ -7534,14 +7976,14 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.1.3", + "php": "^7.4", "ext-ctype": "*", "ext-iconv": "*", "ext-json": "*" }, "platform-dev": [], "platform-overrides": { - "php": "7.3.12" + "php": "7.4.15" }, "plugin-api-version": "2.0.0" } diff --git a/api/config/bundles.php b/api/config/bundles.php index de8a66b..f42212d 100644 --- a/api/config/bundles.php +++ b/api/config/bundles.php @@ -11,4 +11,5 @@ return [ JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], Baldinof\RoadRunnerBundle\BaldinofRoadRunnerBundle::class => ['all' => true], + Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], ]; diff --git a/api/config/packages/messenger.yaml b/api/config/packages/messenger.yaml new file mode 100644 index 0000000..82536a4 --- /dev/null +++ b/api/config/packages/messenger.yaml @@ -0,0 +1,13 @@ +framework: + messenger: + # Uncomment this (and the failed transport below) to send failed messages to this transport for later handling. + # failure_transport: failed + + transports: + # https://symfony.com/doc/current/messenger.html#transport-configuration + async: '%env(MESSENGER_TRANSPORT_DSN)%' + # failed: 'doctrine://default?queue_name=failed' + sync: 'sync://' + + routing: + 'App\Message\UpdateDataMessage': async diff --git a/api/dev.Dockerfile b/api/dev.Dockerfile index fbe361e..2e8e9d7 100644 --- a/api/dev.Dockerfile +++ b/api/dev.Dockerfile @@ -1,6 +1,5 @@ FROM php:7.4-fpm-alpine -ENV APP_ENV=dev ENV DATABASE_URL="sqlite:///var/db/app.db" COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ diff --git a/api/src/Command/UpdateCommand.php b/api/src/Command/UpdateCommand.php index 54be5aa..5890fd4 100644 --- a/api/src/Command/UpdateCommand.php +++ b/api/src/Command/UpdateCommand.php @@ -2,29 +2,47 @@ namespace App\Command; +use App\Message\UpdateDataMessage; use App\Service\DataUpdater; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Messenger\MessageBusInterface; class UpdateCommand extends Command { /** @var DataUpdater */ private $updater; + /** @var MessageBusInterface */ + private $bus; - /** - * UpdateCommand constructor. - * - * @param $updater - */ - public function __construct(DataUpdater $updater) + public function __construct(DataUpdater $updater, MessageBusInterface $bus) { parent::__construct('app:update'); + $this->updater = $updater; + $this->bus = $bus; + } + + protected function configure() + { + $this->addOption( + 'async', 'a', + InputOption::VALUE_NONE, + 'Run in worker process via message queue.' + ); } protected function execute(InputInterface $input, OutputInterface $output) { - $this->updater->update($output); + if ($input->getOption('async')) { + $this->bus->dispatch(new UpdateDataMessage()); + $output->writeln("Update request sent to message queue."); + } else { + $this->updater->update($output); + } + + return Command::SUCCESS; } -} \ No newline at end of file +} diff --git a/api/src/Message/UpdateDataMessage.php b/api/src/Message/UpdateDataMessage.php new file mode 100644 index 0000000..173ded5 --- /dev/null +++ b/api/src/Message/UpdateDataMessage.php @@ -0,0 +1,7 @@ +updater = $updater; + } + + public function __invoke(UpdateDataMessage $message) + { + try { + $this->updater->update(new LoggerOutput($this->logger)); + } catch (\Exception $exception) { + $this->logger->critical($exception->getMessage(), [ + 'backtrace' => $exception->getTraceAsString() + ]); + } + } +} diff --git a/api/src/Output/LoggerOutput.php b/api/src/Output/LoggerOutput.php new file mode 100644 index 0000000..8421cf7 --- /dev/null +++ b/api/src/Output/LoggerOutput.php @@ -0,0 +1,30 @@ +logger = $logger; + } + + protected function doWrite(string $message, bool $newline) + { + $this->logger->info($message); + } +} diff --git a/api/src/Service/DataUpdater.php b/api/src/Service/DataUpdater.php index a31bba0..1839b92 100644 --- a/api/src/Service/DataUpdater.php +++ b/api/src/Service/DataUpdater.php @@ -5,6 +5,7 @@ namespace App\Service; use App\Event\DataUpdateEvent; use Doctrine\DBAL\Schema\Table; use Doctrine\ORM\EntityManagerInterface; +use Kadet\Functional as f; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -18,11 +19,6 @@ class DataUpdater /** @var EntityManagerInterface */ private $em; - /** - * DataUpdater constructor. - * - * @param EventDispatcherInterface $dispatcher - */ public function __construct(EventDispatcherInterface $dispatcher, EntityManagerInterface $em) { $this->dispatcher = $dispatcher; @@ -41,11 +37,13 @@ class DataUpdater copy($path, $backup); try { - collect($schema->listTables())->reject(function (Table $schema) { - return $schema->getName() === 'migration_versions'; - })->each([$schema, 'dropAndCreateTable']); + collect($schema->listTables()) + ->reject(f\ref([$this, 'shouldTableBePreserved'])) + ->each(f\ref([$schema, 'dropAndCreateTable'])) + ; $this->dispatcher->dispatch(new DataUpdateEvent($output), DataUpdateEvent::NAME); + unlink($backup); } catch (\Throwable $exception) { $connection->close(); @@ -56,4 +54,9 @@ class DataUpdater throw $exception; } } + + private function shouldTableBePreserved(Table $schema) + { + return in_array($schema->getName(), ['migration_versions', 'messenger_messages']); + } } diff --git a/api/symfony.lock b/api/symfony.lock index 97ab9dc..e8f3e9c 100644 --- a/api/symfony.lock +++ b/api/symfony.lock @@ -197,6 +197,9 @@ "nesbot/carbon": { "version": "1.33.0" }, + "nikic/php-parser": { + "version": "v4.10.4" + }, "ocramius/package-versions": { "version": "1.3.0" }, @@ -266,6 +269,9 @@ "spiral/roadrunner": { "version": "v1.8.4" }, + "symfony/amqp-messenger": { + "version": "v5.2.4" + }, "symfony/asset": { "version": "v4.1.4" }, @@ -296,6 +302,9 @@ "symfony/doctrine-bridge": { "version": "v4.1.4" }, + "symfony/doctrine-messenger": { + "version": "v5.2.5" + }, "symfony/dotenv": { "version": "v4.1.3" }, @@ -356,6 +365,27 @@ "symfony/http-kernel": { "version": "v4.1.3" }, + "symfony/maker-bundle": { + "version": "1.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "1.0", + "ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f" + } + }, + "symfony/messenger": { + "version": "4.3", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "4.3", + "ref": "e9a414b113ceadbf4e52abe37bf8f1b443f06ccb" + }, + "files": [ + "config/packages/messenger.yaml" + ] + }, "symfony/monolog-bridge": { "version": "v4.1.4" }, @@ -401,6 +431,9 @@ "symfony/psr-http-message-bridge": { "version": "v2.0.2" }, + "symfony/redis-messenger": { + "version": "v5.2.4" + }, "symfony/routing": { "version": "4.0", "recipe": {