From 8593b41207dc62f4e2f4e4ea21dd03875c8fd878 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 14 Aug 2018 09:36:07 +0300 Subject: [PATCH 01/38] Merge branch 'master' into pr-250 --- composer.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 37ee38a..6bbca27 100644 --- a/composer.json +++ b/composer.json @@ -6,19 +6,19 @@ "homepage": "https://enqueue.forma-pro.com/", "license": "MIT", "require": { - "php": ">=5.6", - "enqueue/enqueue": "^0.8@dev", - "symfony/console": "^2.8|^3|^4" + "php": ">=7.1", + "enqueue/enqueue": "0.9.x-dev", + "symfony/console": "^3.4|^4" }, "require-dev": { "phpunit/phpunit": "~5.5", - "symfony/dependency-injection": "^2.8|^3|^4", - "symfony/config": "^2.8|^3|^4", - "symfony/http-kernel": "^2.8|^3|^4", - "symfony/filesystem": "^2.8|^3|^4", - "enqueue/null": "^0.8@dev", - "enqueue/fs": "^0.8@dev", - "enqueue/test": "^0.8@dev" + "symfony/dependency-injection": "^3.4|^4", + "symfony/config": "^3.4|^4", + "symfony/http-kernel": "^3.4|^4", + "symfony/filesystem": "^3.4|^4", + "enqueue/null": "0.9.x-dev", + "enqueue/fs": "0.9.x-dev", + "enqueue/test": "0.9.x-dev" }, "support": { "email": "opensource@forma-pro.com", @@ -28,7 +28,7 @@ "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, "suggest": { - "symfony/dependency-injection": "^2.8|^3|^4 If you'd like to use async event dispatcher container extension." + "symfony/dependency-injection": "^3.4|^4 If you'd like to use async event dispatcher container extension." }, "autoload": { "psr-4": { "Enqueue\\AsyncCommand\\": "" }, @@ -38,7 +38,7 @@ }, "extra": { "branch-alias": { - "dev-master": "0.8.x-dev" + "dev-master": "0.9.x-dev" } } } From fde7a4316b55faeaf573f5b05f09597ea6e46561 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 14 Aug 2018 10:38:52 +0300 Subject: [PATCH 02/38] update pkgs travis files. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b9cf57f..9ed4fa1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ git: language: php php: - - '5.6' - - '7.0' + - '7.1' + - '7.2' cache: directories: From 7daa5e67fdd50678e70d30fd749e2a7c0129d77c Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 14 Aug 2018 10:39:19 +0300 Subject: [PATCH 03/38] add typehints to async command classes. --- Resources/config/services.yml | 2 +- RunCommand.php | 34 ++------------ RunCommandProcessor.php | 36 ++++++++++++--- RunCommandResult.php | 85 ----------------------------------- composer.json | 3 +- 5 files changed, 36 insertions(+), 124 deletions(-) delete mode 100644 RunCommandResult.php diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 97355cb..9f6543f 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -3,6 +3,6 @@ services: class: 'Enqueue\AsyncCommand\RunCommandProcessor' public: public arguments: - - '%kernel.root_dir%/..' + - '%kernel.project_dir%' tags: - { name: 'enqueue.client.processor' } diff --git a/RunCommand.php b/RunCommand.php index b595916..437c3a6 100644 --- a/RunCommand.php +++ b/RunCommand.php @@ -24,36 +24,13 @@ final class RunCommand implements \JsonSerializable * @param string[] $arguments * @param string[] $options */ - public function __construct($command, array $arguments = [], array $options = []) + public function __construct(string $command, array $arguments = [], array $options = []) { $this->command = $command; $this->arguments = $arguments; $this->options = $options; } - /** - * @return string - */ - public function getCommandLine() - { - $optionsString = ''; - foreach ($this->options as $name => $value) { - $optionsString .= " $name=$value"; - } - $optionsString = trim($optionsString); - - $argumentsString = ''; - foreach ($this->arguments as $value) { - $argumentsString .= " $value"; - } - $argumentsString = trim($argumentsString); - - return trim($this->command.' '.$argumentsString.' '.$optionsString); - } - - /** - * @return string - */ public function getCommand(): string { return $this->command; @@ -75,7 +52,7 @@ public function getOptions(): array return $this->options; } - public function jsonSerialize() + public function jsonSerialize(): array { return [ 'command' => $this->command, @@ -84,12 +61,7 @@ public function jsonSerialize() ]; } - /** - * @param string $json - * - * @return self - */ - public static function jsonUnserialize($json) + public static function jsonUnserialize(string $json): self { $data = json_decode($json, true); if (JSON_ERROR_NONE !== json_last_error()) { diff --git a/RunCommandProcessor.php b/RunCommandProcessor.php index 0352824..bdb1dfc 100644 --- a/RunCommandProcessor.php +++ b/RunCommandProcessor.php @@ -17,28 +17,32 @@ final class RunCommandProcessor implements PsrProcessor, CommandSubscriberInterf */ private $projectDir; - public function __construct($projectDir) + public function __construct(string $projectDir) { $this->projectDir = $projectDir; } - public function process(PsrMessage $message, PsrContext $context) + public function process(PsrMessage $message, PsrContext $context): Result { $command = RunCommand::jsonUnserialize($message->getBody()); $phpBin = (new PhpExecutableFinder())->find(); $consoleBin = file_exists($this->projectDir.'/bin/console') ? './bin/console' : './app/console'; - $process = new Process($phpBin.' '.$consoleBin.' '.$command->getCommandLine(), $this->projectDir); + $process = new Process($phpBin.' '.$consoleBin.' '.$this->getCommandLine($command), $this->projectDir); $process->run(); - $result = new RunCommandResult($process->getExitCode(), $process->getOutput(), $process->getErrorOutput()); + if ($message->getReplyTo()) { + $result = new CommandResult($process->getExitCode(), $process->getOutput(), $process->getErrorOutput()); - return Result::reply($context->createMessage(json_encode($result))); + return Result::reply($context->createMessage(json_encode($result))); + } + + return Result::ack(); } - public static function getSubscribedCommand() + public static function getSubscribedCommand(): array { return [ 'processorName' => Commands::RUN_COMMAND, @@ -47,4 +51,24 @@ public static function getSubscribedCommand() 'exclusive' => true, ]; } + + /** + * @return string + */ + private function getCommandLine(RunCommand $command): string + { + $optionsString = ''; + foreach ($command->getOptions() as $name => $value) { + $optionsString .= " $name=$value"; + } + $optionsString = trim($optionsString); + + $argumentsString = ''; + foreach ($command->getArguments() as $value) { + $argumentsString .= " $value"; + } + $argumentsString = trim($argumentsString); + + return trim($command->getCommand().' '.$argumentsString.' '.$optionsString); + } } diff --git a/RunCommandResult.php b/RunCommandResult.php deleted file mode 100644 index ce35a03..0000000 --- a/RunCommandResult.php +++ /dev/null @@ -1,85 +0,0 @@ -exitCode = $exitCode; - $this->output = $output; - $this->errorOutput = $errorOutput; - } - - /** - * @return int - */ - public function getExitCode(): int - { - return $this->exitCode; - } - - /** - * @return string - */ - public function getOutput(): string - { - return $this->output; - } - - /** - * @return string - */ - public function getErrorOutput(): string - { - return $this->errorOutput; - } - - public function jsonSerialize() - { - return [ - 'exitCode' => $this->exitCode, - 'output' => $this->output, - 'errorOutput' => $this->errorOutput, - ]; - } - - /** - * @param string $json - * - * @return self - */ - public static function jsonUnserialize($json) - { - $data = json_decode($json, true); - if (JSON_ERROR_NONE !== json_last_error()) { - throw new \InvalidArgumentException(sprintf( - 'The malformed json given. Error %s and message %s', - json_last_error(), - json_last_error_msg() - )); - } - - return new self($data['exitCode'], $data['output'], $data['errorOutput']); - } -} diff --git a/composer.json b/composer.json index 6bbca27..3c7aaef 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "require": { "php": ">=7.1", "enqueue/enqueue": "0.9.x-dev", - "symfony/console": "^3.4|^4" + "symfony/console": "^3.4|^4", + "symfony/process": "^3.4|^4" }, "require-dev": { "phpunit/phpunit": "~5.5", From 0933f8c3d40892b38ed055a2f11b9166126e6428 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 14 Aug 2018 10:39:40 +0300 Subject: [PATCH 04/38] add tests. --- CommandResult.php | 71 +++++++++++++++++++++++++ Tests/CommandResultTest.php | 69 ++++++++++++++++++++++++ Tests/Functional/UseCasesTest.php | 41 +++++++++++++++ Tests/Functional/bin/console | 6 +++ Tests/RunCommandProcessorTest.php | 52 ++++++++++++++++++ Tests/RunCommandTest.php | 87 +++++++++++++++++++++++++++++++ 6 files changed, 326 insertions(+) create mode 100644 CommandResult.php create mode 100644 Tests/CommandResultTest.php create mode 100644 Tests/Functional/UseCasesTest.php create mode 100644 Tests/Functional/bin/console create mode 100644 Tests/RunCommandProcessorTest.php create mode 100644 Tests/RunCommandTest.php diff --git a/CommandResult.php b/CommandResult.php new file mode 100644 index 0000000..1c746a9 --- /dev/null +++ b/CommandResult.php @@ -0,0 +1,71 @@ +exitCode = $exitCode; + $this->output = $output; + $this->errorOutput = $errorOutput; + } + + public function getExitCode(): int + { + return $this->exitCode; + } + + public function getOutput(): string + { + return $this->output; + } + + public function getErrorOutput(): string + { + return $this->errorOutput; + } + + public function jsonSerialize(): array + { + return [ + 'exitCode' => $this->exitCode, + 'output' => $this->output, + 'errorOutput' => $this->errorOutput, + ]; + } + + public static function jsonUnserialize(string $json): self + { + $data = json_decode($json, true); + if (JSON_ERROR_NONE !== json_last_error()) { + throw new \InvalidArgumentException(sprintf( + 'The malformed json given. Error %s and message %s', + json_last_error(), + json_last_error_msg() + )); + } + + return new self($data['exitCode'], $data['output'], $data['errorOutput']); + } +} diff --git a/Tests/CommandResultTest.php b/Tests/CommandResultTest.php new file mode 100644 index 0000000..03a6155 --- /dev/null +++ b/Tests/CommandResultTest.php @@ -0,0 +1,69 @@ +assertTrue($rc->implementsInterface(\JsonSerializable::class)); + } + + public function testShouldBeFinal() + { + $rc = new \ReflectionClass(CommandResult::class); + + $this->assertTrue($rc->isFinal()); + } + + public function testShouldAllowGetExitCodeSetInConstructor() + { + $result = new CommandResult(123, '', ''); + + $this->assertSame(123, $result->getExitCode()); + } + + public function testShouldAllowGetOutputSetInConstructor() + { + $result = new CommandResult(0, 'theOutput', ''); + + $this->assertSame('theOutput', $result->getOutput()); + } + + public function testShouldAllowGetErrorOutputSetInConstructor() + { + $result = new CommandResult(0, '', 'theErrorOutput'); + + $this->assertSame('theErrorOutput', $result->getErrorOutput()); + } + + public function testShouldSerializeAndUnserialzeCommand() + { + $result = new CommandResult(123, 'theOutput', 'theErrorOutput'); + + $jsonCommand = json_encode($result); + + // guard + $this->assertNotEmpty($jsonCommand); + + $unserializedResult = CommandResult::jsonUnserialize($jsonCommand); + + $this->assertInstanceOf(CommandResult::class, $unserializedResult); + $this->assertSame(123, $unserializedResult->getExitCode()); + $this->assertSame('theOutput', $unserializedResult->getOutput()); + $this->assertSame('theErrorOutput', $unserializedResult->getErrorOutput()); + } + + public function testThrowExceptionIfInvalidJsonGiven() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The malformed json given.'); + + CommandResult::jsonUnserialize('{]'); + } +} diff --git a/Tests/Functional/UseCasesTest.php b/Tests/Functional/UseCasesTest.php new file mode 100644 index 0000000..a6d3d94 --- /dev/null +++ b/Tests/Functional/UseCasesTest.php @@ -0,0 +1,41 @@ +setReplyTo('aReplyToQueue'); + + $processor = new RunCommandProcessor(__DIR__); + + $result = $processor->process($psrMessage, new NullContext()); + + $this->assertInstanceOf(Result::class, $result); + $this->assertInstanceOf(PsrMessage::class, $result->getReply()); + + $replyMessage = $result->getReply(); + + $commandResult = CommandResult::jsonUnserialize($replyMessage->getBody()); + + $this->assertSame(123, $commandResult->getExitCode()); + $this->assertSame('Command Output', $commandResult->getOutput()); + $this->assertSame('Command Error Output', $commandResult->getErrorOutput()); + } +} diff --git a/Tests/Functional/bin/console b/Tests/Functional/bin/console new file mode 100644 index 0000000..40d7e35 --- /dev/null +++ b/Tests/Functional/bin/console @@ -0,0 +1,6 @@ +assertTrue($rc->implementsInterface(PsrProcessor::class)); + } + + public function testShouldImplementCommandSubscriberInterfaceInterface() + { + $rc = new \ReflectionClass(RunCommandProcessor::class); + + $this->assertTrue($rc->implementsInterface(CommandSubscriberInterface::class)); + } + + public function testShouldBeFinal() + { + $rc = new \ReflectionClass(RunCommandProcessor::class); + + $this->assertTrue($rc->isFinal()); + } + + public function testCouldBeConstructedWithProjectDirAsFirstArgument() + { + $processor = new RunCommandProcessor('aProjectDir'); + + $this->assertAttributeSame('aProjectDir', 'projectDir', $processor); + } + + public function testShouldSubscribeOnRunCommand() + { + $subscription = RunCommandProcessor::getSubscribedCommand(); + + $this->assertSame([ + 'processorName' => Commands::RUN_COMMAND, + 'queueName' => Commands::RUN_COMMAND, + 'queueNameHardcoded' => true, + 'exclusive' => true, + ], $subscription); + } +} diff --git a/Tests/RunCommandTest.php b/Tests/RunCommandTest.php new file mode 100644 index 0000000..a673e06 --- /dev/null +++ b/Tests/RunCommandTest.php @@ -0,0 +1,87 @@ +assertTrue($rc->implementsInterface(\JsonSerializable::class)); + } + + public function testShouldBeFinal() + { + $rc = new \ReflectionClass(RunCommand::class); + + $this->assertTrue($rc->isFinal()); + } + + public function testShouldAllowGetCommandSetInConstructor() + { + $command = new RunCommand('theCommand'); + + $this->assertSame('theCommand', $command->getCommand()); + } + + public function testShouldReturnEmptyArrayByDefaultOnGetArguments() + { + $command = new RunCommand('aCommand'); + + $this->assertSame([], $command->getArguments()); + } + + public function testShouldReturnEmptyArrayByDefaultOnGetOptions() + { + $command = new RunCommand('aCommand'); + + $this->assertSame([], $command->getOptions()); + } + + public function testShouldReturnArgumentsSetInConstructor() + { + $command = new RunCommand('aCommand', ['theArgument' => 'theValue']); + + $this->assertSame(['theArgument' => 'theValue'], $command->getArguments()); + } + + public function testShouldReturnOptionsSetInConstructor() + { + $command = new RunCommand('aCommand', [], ['theOption' => 'theValue']); + + $this->assertSame(['theOption' => 'theValue'], $command->getOptions()); + } + + public function testShouldSerializeAndUnserialzeCommand() + { + $command = new RunCommand( + 'theCommand', + ['theArgument' => 'theValue'], + ['theOption' => 'theValue'] + ); + + $jsonCommand = json_encode($command); + + // guard + $this->assertNotEmpty($jsonCommand); + + $unserializedCommand = RunCommand::jsonUnserialize($jsonCommand); + + $this->assertInstanceOf(RunCommand::class, $unserializedCommand); + $this->assertSame('theCommand', $unserializedCommand->getCommand()); + $this->assertSame(['theArgument' => 'theValue'], $unserializedCommand->getArguments()); + $this->assertSame(['theOption' => 'theValue'], $unserializedCommand->getOptions()); + } + + public function testThrowExceptionIfInvalidJsonGiven() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The malformed json given.'); + + RunCommand::jsonUnserialize('{]'); + } +} From c6d4a4650b1de6bdd05d6c847058c053e5020b7f Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 1 Sep 2018 20:48:13 +0300 Subject: [PATCH 05/38] explisitly add queue interop dev package as dep --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 3c7aaef..f56c0bf 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "require": { "php": ">=7.1", "enqueue/enqueue": "0.9.x-dev", + "queue-interop/queue-interop": "0.7.x-dev", "symfony/console": "^3.4|^4", "symfony/process": "^3.4|^4" }, From 3586267fcf6686602e5485c6339ae7d124e83a9b Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Thu, 27 Sep 2018 13:56:38 +0300 Subject: [PATCH 06/38] [async-commands][async-events] Sync with latest design chagnes in core. --- Resources/config/services.yml | 3 +-- RunCommandProcessor.php | 6 +++--- Tests/RunCommandProcessorTest.php | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 9f6543f..84ada42 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,8 +1,7 @@ services: enqueue.async_command.run_command_processor: class: 'Enqueue\AsyncCommand\RunCommandProcessor' - public: public arguments: - '%kernel.project_dir%' tags: - - { name: 'enqueue.client.processor' } + - { name: 'enqueue.command_subscriber', client: 'default' } diff --git a/RunCommandProcessor.php b/RunCommandProcessor.php index bdb1dfc..3e34759 100644 --- a/RunCommandProcessor.php +++ b/RunCommandProcessor.php @@ -45,9 +45,9 @@ public function process(PsrMessage $message, PsrContext $context): Result public static function getSubscribedCommand(): array { return [ - 'processorName' => Commands::RUN_COMMAND, - 'queueName' => Commands::RUN_COMMAND, - 'queueNameHardcoded' => true, + 'command' => Commands::RUN_COMMAND, + 'queue' => Commands::RUN_COMMAND, + 'prefix_queue' => false, 'exclusive' => true, ]; } diff --git a/Tests/RunCommandProcessorTest.php b/Tests/RunCommandProcessorTest.php index 2db6506..c160699 100644 --- a/Tests/RunCommandProcessorTest.php +++ b/Tests/RunCommandProcessorTest.php @@ -43,9 +43,9 @@ public function testShouldSubscribeOnRunCommand() $subscription = RunCommandProcessor::getSubscribedCommand(); $this->assertSame([ - 'processorName' => Commands::RUN_COMMAND, - 'queueName' => Commands::RUN_COMMAND, - 'queueNameHardcoded' => true, + 'command' => Commands::RUN_COMMAND, + 'queue' => Commands::RUN_COMMAND, + 'prefix_queue' => false, 'exclusive' => true, ], $subscription); } From 6ac773a3a9e45121df9f68cb5ae15757f97beb62 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 28 Sep 2018 14:06:36 +0300 Subject: [PATCH 07/38] [async-command][async-events] Do not use deprecated classes. --- RunCommandProcessor.php | 10 +++++----- Tests/Functional/UseCasesTest.php | 10 +++++----- Tests/RunCommandProcessorTest.php | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/RunCommandProcessor.php b/RunCommandProcessor.php index 3e34759..b093adc 100644 --- a/RunCommandProcessor.php +++ b/RunCommandProcessor.php @@ -4,13 +4,13 @@ use Enqueue\Client\CommandSubscriberInterface; use Enqueue\Consumption\Result; -use Interop\Queue\PsrContext; -use Interop\Queue\PsrMessage; -use Interop\Queue\PsrProcessor; +use Interop\Queue\Context; +use Interop\Queue\Message; +use Interop\Queue\Processor; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; -final class RunCommandProcessor implements PsrProcessor, CommandSubscriberInterface +final class RunCommandProcessor implements Processor, CommandSubscriberInterface { /** * @var string @@ -22,7 +22,7 @@ public function __construct(string $projectDir) $this->projectDir = $projectDir; } - public function process(PsrMessage $message, PsrContext $context): Result + public function process(Message $message, Context $context): Result { $command = RunCommand::jsonUnserialize($message->getBody()); diff --git a/Tests/Functional/UseCasesTest.php b/Tests/Functional/UseCasesTest.php index a6d3d94..03eb525 100644 --- a/Tests/Functional/UseCasesTest.php +++ b/Tests/Functional/UseCasesTest.php @@ -8,7 +8,7 @@ use Enqueue\Consumption\Result; use Enqueue\Null\NullContext; use Enqueue\Null\NullMessage; -use Interop\Queue\PsrMessage; +use Interop\Queue\Message; use PHPUnit\Framework\TestCase; /** @@ -20,15 +20,15 @@ public function testRunSimpleCommandAndReturnOutput() { $runCommand = new RunCommand('foo'); - $psrMessage = new NullMessage(json_encode($runCommand)); - $psrMessage->setReplyTo('aReplyToQueue'); + $Message = new NullMessage(json_encode($runCommand)); + $Message->setReplyTo('aReplyToQueue'); $processor = new RunCommandProcessor(__DIR__); - $result = $processor->process($psrMessage, new NullContext()); + $result = $processor->process($Message, new NullContext()); $this->assertInstanceOf(Result::class, $result); - $this->assertInstanceOf(PsrMessage::class, $result->getReply()); + $this->assertInstanceOf(Message::class, $result->getReply()); $replyMessage = $result->getReply(); diff --git a/Tests/RunCommandProcessorTest.php b/Tests/RunCommandProcessorTest.php index c160699..ce5dc9e 100644 --- a/Tests/RunCommandProcessorTest.php +++ b/Tests/RunCommandProcessorTest.php @@ -5,7 +5,7 @@ use Enqueue\AsyncCommand\Commands; use Enqueue\AsyncCommand\RunCommandProcessor; use Enqueue\Client\CommandSubscriberInterface; -use Interop\Queue\PsrProcessor; +use Interop\Queue\Processor; use PHPUnit\Framework\TestCase; class RunCommandProcessorTest extends TestCase @@ -14,7 +14,7 @@ public function testShouldImplementProcessorInterface() { $rc = new \ReflectionClass(RunCommandProcessor::class); - $this->assertTrue($rc->implementsInterface(PsrProcessor::class)); + $this->assertTrue($rc->implementsInterface(Processor::class)); } public function testShouldImplementCommandSubscriberInterfaceInterface() From 593e31feb0a91ba8beea65eea205d184e6a89802 Mon Sep 17 00:00:00 2001 From: webmake Date: Sat, 27 Oct 2018 10:56:55 +0000 Subject: [PATCH 08/38] Do not export non source files --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f13d4d9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +/Tests export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore From 385f7379f09adb22cf20ae7da0392e9d2dad4f45 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 6 Nov 2018 18:06:13 +0200 Subject: [PATCH 09/38] [doc][skip ci] Add sponsoring section. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 17a9103..5e6811c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ +

Supporting Enqueue

+ +Enqueue is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our customers. If you'd like to join them, please consider: + +- [Become a sponsor](https://www.patreon.com/makasim). +- [Become our client](http://forma-pro.com/) + +--- + # Symfony Async Command. [![Gitter](https://badges.gitter.im/php-enqueue/Lobby.svg)](https://gitter.im/php-enqueue/Lobby) From 5be9704c1a63be1850bb0083fc29d92b8af1d5ed Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 6 Nov 2018 18:12:08 +0200 Subject: [PATCH 10/38] [docs][skip ci] Add sponsoring to docs. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e6811c..09af3be 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Enqueue is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our customers. If you'd like to join them, please consider: -- [Become a sponsor](https://www.patreon.com/makasim). +- [Become a sponsor](https://www.patreon.com/makasim) - [Become our client](http://forma-pro.com/) --- From 657e6f17ea30e3c18334320c997444776180e015 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Mon, 12 Nov 2018 13:50:57 +0200 Subject: [PATCH 11/38] multi client configuration --- DependencyInjection/AsyncCommandExtension.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/DependencyInjection/AsyncCommandExtension.php b/DependencyInjection/AsyncCommandExtension.php index 77db687..3d614b4 100644 --- a/DependencyInjection/AsyncCommandExtension.php +++ b/DependencyInjection/AsyncCommandExtension.php @@ -2,6 +2,7 @@ namespace Enqueue\AsyncCommand\DependencyInjection; +use Enqueue\AsyncCommand\RunCommandProcessor; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -16,5 +17,13 @@ public function load(array $configs, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); + + $service = $container->register('enqueue.async_command.run_command_processor', RunCommandProcessor::class) + ->addArgument('%kernel.project_dir%') + ; + + foreach ($configs['clients'] as $client) { + $service->addTag('enqueue.command_subscriber', ['client' => $client]); + } } } From 6df5fba9bc5d4d284087c80e4b124daf482ad576 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Fri, 16 Nov 2018 13:52:04 +0200 Subject: [PATCH 12/38] multi client configuration --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f56c0bf..8e44fe3 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": ">=7.1", "enqueue/enqueue": "0.9.x-dev", - "queue-interop/queue-interop": "0.7.x-dev", + "queue-interop/queue-interop": "^0.7", "symfony/console": "^3.4|^4", "symfony/process": "^3.4|^4" }, From ebc2e8b69a2e15617b177540656380c8355f4900 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 27 Nov 2018 19:54:18 +0200 Subject: [PATCH 13/38] Allow installing stable dependencies. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8e44fe3..5d93f47 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": ">=7.1", - "enqueue/enqueue": "0.9.x-dev", + "enqueue/enqueue": "^0.9", "queue-interop/queue-interop": "^0.7", "symfony/console": "^3.4|^4", "symfony/process": "^3.4|^4" From fa863738e7a449f4df72b1dc8c30015f164d8b24 Mon Sep 17 00:00:00 2001 From: Kotlyar Maksim Date: Thu, 13 Dec 2018 17:31:01 +0200 Subject: [PATCH 14/38] Allow queue interop 0.8 in packages --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5d93f47..7474c88 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": ">=7.1", "enqueue/enqueue": "^0.9", - "queue-interop/queue-interop": "^0.7", + "queue-interop/queue-interop": "^0.7|^0.8", "symfony/console": "^3.4|^4", "symfony/process": "^3.4|^4" }, From a4618dc514da7e2269725aa4b6440e9a725e3284 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 15 Dec 2018 22:34:14 +0200 Subject: [PATCH 15/38] [async-command] Remove command subsriber interface. remove services.yaml --- DependencyInjection/AsyncCommandExtension.php | 25 +++++++++---------- Resources/config/services.yml | 7 ------ RunCommandProcessor.php | 13 +--------- 3 files changed, 13 insertions(+), 32 deletions(-) delete mode 100644 Resources/config/services.yml diff --git a/DependencyInjection/AsyncCommandExtension.php b/DependencyInjection/AsyncCommandExtension.php index 3d614b4..b4005ab 100644 --- a/DependencyInjection/AsyncCommandExtension.php +++ b/DependencyInjection/AsyncCommandExtension.php @@ -2,28 +2,27 @@ namespace Enqueue\AsyncCommand\DependencyInjection; +use Enqueue\AsyncCommand\Commands; use Enqueue\AsyncCommand\RunCommandProcessor; -use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; class AsyncCommandExtension extends Extension { - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container) { - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.yml'); - - $service = $container->register('enqueue.async_command.run_command_processor', RunCommandProcessor::class) - ->addArgument('%kernel.project_dir%') - ; - foreach ($configs['clients'] as $client) { - $service->addTag('enqueue.command_subscriber', ['client' => $client]); + $id = sprintf('enqueue.async_command.%s.run_command_processor', $client); + $container->register($id, RunCommandProcessor::class) + ->addArgument('%kernel.project_dir%') + ->addTag('enqueue.processor', [ + 'client' => $client, + 'command' => Commands::RUN_COMMAND, + 'queue' => Commands::RUN_COMMAND, + 'queue_prefixed' => false, + 'exclusive' => true, + ]) + ; } } } diff --git a/Resources/config/services.yml b/Resources/config/services.yml deleted file mode 100644 index 84ada42..0000000 --- a/Resources/config/services.yml +++ /dev/null @@ -1,7 +0,0 @@ -services: - enqueue.async_command.run_command_processor: - class: 'Enqueue\AsyncCommand\RunCommandProcessor' - arguments: - - '%kernel.project_dir%' - tags: - - { name: 'enqueue.command_subscriber', client: 'default' } diff --git a/RunCommandProcessor.php b/RunCommandProcessor.php index b093adc..7925d65 100644 --- a/RunCommandProcessor.php +++ b/RunCommandProcessor.php @@ -2,7 +2,6 @@ namespace Enqueue\AsyncCommand; -use Enqueue\Client\CommandSubscriberInterface; use Enqueue\Consumption\Result; use Interop\Queue\Context; use Interop\Queue\Message; @@ -10,7 +9,7 @@ use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; -final class RunCommandProcessor implements Processor, CommandSubscriberInterface +final class RunCommandProcessor implements Processor { /** * @var string @@ -42,16 +41,6 @@ public function process(Message $message, Context $context): Result return Result::ack(); } - public static function getSubscribedCommand(): array - { - return [ - 'command' => Commands::RUN_COMMAND, - 'queue' => Commands::RUN_COMMAND, - 'prefix_queue' => false, - 'exclusive' => true, - ]; - } - /** * @return string */ From bdd3cc8f03654336cb5668a19a926b756462dfcb Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 15 Dec 2018 22:46:41 +0200 Subject: [PATCH 16/38] add transport processor tag. --- DependencyInjection/AsyncCommandExtension.php | 1 + 1 file changed, 1 insertion(+) diff --git a/DependencyInjection/AsyncCommandExtension.php b/DependencyInjection/AsyncCommandExtension.php index b4005ab..9bf17a1 100644 --- a/DependencyInjection/AsyncCommandExtension.php +++ b/DependencyInjection/AsyncCommandExtension.php @@ -22,6 +22,7 @@ public function load(array $configs, ContainerBuilder $container) 'queue_prefixed' => false, 'exclusive' => true, ]) + ->addTag('enqueue.transport.processor') ; } } From c106135b46ee90ffa2b20736edb5680d8d0bfc72 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 15 Dec 2018 22:53:01 +0200 Subject: [PATCH 17/38] remove not needed tests. --- Tests/RunCommandProcessorTest.php | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Tests/RunCommandProcessorTest.php b/Tests/RunCommandProcessorTest.php index ce5dc9e..83274e2 100644 --- a/Tests/RunCommandProcessorTest.php +++ b/Tests/RunCommandProcessorTest.php @@ -2,9 +2,7 @@ namespace Enqueue\AsyncCommand\Tests; -use Enqueue\AsyncCommand\Commands; use Enqueue\AsyncCommand\RunCommandProcessor; -use Enqueue\Client\CommandSubscriberInterface; use Interop\Queue\Processor; use PHPUnit\Framework\TestCase; @@ -17,13 +15,6 @@ public function testShouldImplementProcessorInterface() $this->assertTrue($rc->implementsInterface(Processor::class)); } - public function testShouldImplementCommandSubscriberInterfaceInterface() - { - $rc = new \ReflectionClass(RunCommandProcessor::class); - - $this->assertTrue($rc->implementsInterface(CommandSubscriberInterface::class)); - } - public function testShouldBeFinal() { $rc = new \ReflectionClass(RunCommandProcessor::class); @@ -37,16 +28,4 @@ public function testCouldBeConstructedWithProjectDirAsFirstArgument() $this->assertAttributeSame('aProjectDir', 'projectDir', $processor); } - - public function testShouldSubscribeOnRunCommand() - { - $subscription = RunCommandProcessor::getSubscribedCommand(); - - $this->assertSame([ - 'command' => Commands::RUN_COMMAND, - 'queue' => Commands::RUN_COMMAND, - 'prefix_queue' => false, - 'exclusive' => true, - ], $subscription); - } } From 9f14631d98143bd05116c57ccee643df7ceb9906 Mon Sep 17 00:00:00 2001 From: GCalmels Date: Mon, 7 Jan 2019 14:24:31 +0100 Subject: [PATCH 18/38] Fix async command/event pkgs --- DependencyInjection/AsyncCommandExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/AsyncCommandExtension.php b/DependencyInjection/AsyncCommandExtension.php index 9bf17a1..2cfdf26 100644 --- a/DependencyInjection/AsyncCommandExtension.php +++ b/DependencyInjection/AsyncCommandExtension.php @@ -19,7 +19,7 @@ public function load(array $configs, ContainerBuilder $container) 'client' => $client, 'command' => Commands::RUN_COMMAND, 'queue' => Commands::RUN_COMMAND, - 'queue_prefixed' => false, + 'prefix_queue' => false, 'exclusive' => true, ]) ->addTag('enqueue.transport.processor') From 872a5a25624e7cb039a9913f34a5d772a7c0d24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 27 May 2019 15:12:22 +0200 Subject: [PATCH 19/38] Prefer github pages in packages' readme files --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 09af3be..7ac95ff 100644 --- a/README.md +++ b/README.md @@ -13,21 +13,21 @@ Enqueue is an MIT-licensed open source project with its ongoing development made [![Build Status](https://travis-ci.org/php-enqueue/async-command.png?branch=master)](https://travis-ci.org/php-enqueue/async-command) [![Total Downloads](https://poser.pugx.org/enqueue/async-command/d/total.png)](https://packagist.org/packages/enqueue/async-command) [![Latest Stable Version](https://poser.pugx.org/enqueue/async-command/version.png)](https://packagist.org/packages/enqueue/async-command) - -It contains an extension to Symfony's [Console](https://symfony.com/doc/current/components/console.html) component. -It allows to execute Symfony's command async by sending the request to message queue. + +It contains an extension to Symfony's [Console](https://symfony.com/doc/current/components/console.html) component. +It allows to execute Symfony's command async by sending the request to message queue. ## Resources * [Site](https://enqueue.forma-pro.com/) -* [Documentation](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md) +* [Documentation](https://php-enqueue.github.com/) * [Questions](https://gitter.im/php-enqueue/Lobby) * [Issue Tracker](https://github.com/php-enqueue/enqueue-dev/issues) ## Developed by Forma-Pro -Forma-Pro is a full stack development company which interests also spread to open source development. -Being a team of strong professionals we have an aim an ability to help community by developing cutting edge solutions in the areas of e-commerce, docker & microservice oriented architecture where we have accumulated a huge many-years experience. +Forma-Pro is a full stack development company which interests also spread to open source development. +Being a team of strong professionals we have an aim an ability to help community by developing cutting edge solutions in the areas of e-commerce, docker & microservice oriented architecture where we have accumulated a huge many-years experience. Our main specialization is Symfony framework based solution, but we are always looking to the technologies that allow us to do our job the best way. We are committed to creating solutions that revolutionize the way how things are developed in aspects of architecture & scalability. If you have any questions and inquires about our open source development, this product particularly or any other matter feel free to contact at opensource@forma-pro.com From 9baddd10bf4fb044c17c5bd4b4f9bca7ac221a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Wed, 29 May 2019 17:08:39 +0200 Subject: [PATCH 20/38] Fix documentation links Whoops. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ac95ff..bd89567 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ It allows to execute Symfony's command async by sending the request to message q ## Resources * [Site](https://enqueue.forma-pro.com/) -* [Documentation](https://php-enqueue.github.com/) +* [Documentation](https://php-enqueue.github.io/) * [Questions](https://gitter.im/php-enqueue/Lobby) * [Issue Tracker](https://github.com/php-enqueue/enqueue-dev/issues) From a160ca4ee989e0e5464cc1c5ae9d52ae653cc06b Mon Sep 17 00:00:00 2001 From: Arkadiusz Surma Date: Thu, 11 Jul 2019 12:10:00 +0100 Subject: [PATCH 21/38] Async commands extended --- DependencyInjection/AsyncCommandExtension.php | 19 ++++++++++++++----- RunCommandProcessor.php | 10 ++++++++-- Tests/RunCommandProcessorTest.php | 7 +++++++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/DependencyInjection/AsyncCommandExtension.php b/DependencyInjection/AsyncCommandExtension.php index 2cfdf26..51c66e4 100644 --- a/DependencyInjection/AsyncCommandExtension.php +++ b/DependencyInjection/AsyncCommandExtension.php @@ -12,13 +12,22 @@ class AsyncCommandExtension extends Extension public function load(array $configs, ContainerBuilder $container) { foreach ($configs['clients'] as $client) { - $id = sprintf('enqueue.async_command.%s.run_command_processor', $client); + // BC compatibility + if (!is_array($client)) { + $client = [ + 'name' => $client, + 'prefix' => '', + 'timeout' => 60, + ]; + } + + $id = sprintf('enqueue.async_command.%s.run_command_processor', $client['name']); $container->register($id, RunCommandProcessor::class) - ->addArgument('%kernel.project_dir%') + ->addArgument('%kernel.project_dir%', $client['timeout']) ->addTag('enqueue.processor', [ - 'client' => $client, - 'command' => Commands::RUN_COMMAND, - 'queue' => Commands::RUN_COMMAND, + 'client' => $client['name'], + 'command' => $client['prefix'].Commands::RUN_COMMAND, + 'queue' => $client['prefix'].Commands::RUN_COMMAND, 'prefix_queue' => false, 'exclusive' => true, ]) diff --git a/RunCommandProcessor.php b/RunCommandProcessor.php index 7925d65..f1495f3 100644 --- a/RunCommandProcessor.php +++ b/RunCommandProcessor.php @@ -11,14 +11,20 @@ final class RunCommandProcessor implements Processor { + /** + * @var int + */ + private $timeout; + /** * @var string */ private $projectDir; - public function __construct(string $projectDir) + public function __construct(string $projectDir, int $timeout = 60) { $this->projectDir = $projectDir; + $this->timeout = $timeout; } public function process(Message $message, Context $context): Result @@ -29,7 +35,7 @@ public function process(Message $message, Context $context): Result $consoleBin = file_exists($this->projectDir.'/bin/console') ? './bin/console' : './app/console'; $process = new Process($phpBin.' '.$consoleBin.' '.$this->getCommandLine($command), $this->projectDir); - + $process->setTimeout($this->timeout); $process->run(); if ($message->getReplyTo()) { diff --git a/Tests/RunCommandProcessorTest.php b/Tests/RunCommandProcessorTest.php index 83274e2..3065ec3 100644 --- a/Tests/RunCommandProcessorTest.php +++ b/Tests/RunCommandProcessorTest.php @@ -28,4 +28,11 @@ public function testCouldBeConstructedWithProjectDirAsFirstArgument() $this->assertAttributeSame('aProjectDir', 'projectDir', $processor); } + + public function testCouldBeConstructedWithTimeoutAsSecondArgument() + { + $processor = new RunCommandProcessor('aProjectDir', 60); + + $this->assertAttributeSame(60, 'timeout', $processor); + } } From 54b340f640d4293223b6e56137de81b7a2e00a02 Mon Sep 17 00:00:00 2001 From: Arkadiusz Surma Date: Mon, 19 Aug 2019 17:16:56 +0100 Subject: [PATCH 22/38] CR fixess --- DependencyInjection/AsyncCommandExtension.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/AsyncCommandExtension.php b/DependencyInjection/AsyncCommandExtension.php index 51c66e4..d1f4157 100644 --- a/DependencyInjection/AsyncCommandExtension.php +++ b/DependencyInjection/AsyncCommandExtension.php @@ -16,7 +16,8 @@ public function load(array $configs, ContainerBuilder $container) if (!is_array($client)) { $client = [ 'name' => $client, - 'prefix' => '', + 'command_name' => Commands::RUN_COMMAND, + 'queue_name' => Commands::RUN_COMMAND, 'timeout' => 60, ]; } @@ -26,8 +27,8 @@ public function load(array $configs, ContainerBuilder $container) ->addArgument('%kernel.project_dir%', $client['timeout']) ->addTag('enqueue.processor', [ 'client' => $client['name'], - 'command' => $client['prefix'].Commands::RUN_COMMAND, - 'queue' => $client['prefix'].Commands::RUN_COMMAND, + 'command' => $client['command_name'] ?? Commands::RUN_COMMAND, + 'queue' => $client['queue_name'] ?? Commands::RUN_COMMAND, 'prefix_queue' => false, 'exclusive' => true, ]) From 8e44bd3e1604b8c58c81c4502b5ab5c6567a6b65 Mon Sep 17 00:00:00 2001 From: Jeroeny Date: Sat, 23 Nov 2019 11:31:39 +0100 Subject: [PATCH 23/38] allow symfony 5 --- composer.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 7474c88..b4e4d90 100644 --- a/composer.json +++ b/composer.json @@ -9,15 +9,15 @@ "php": ">=7.1", "enqueue/enqueue": "^0.9", "queue-interop/queue-interop": "^0.7|^0.8", - "symfony/console": "^3.4|^4", - "symfony/process": "^3.4|^4" + "symfony/console": "^3.4|^4|^5", + "symfony/process": "^3.4|^4|^5" }, "require-dev": { "phpunit/phpunit": "~5.5", - "symfony/dependency-injection": "^3.4|^4", - "symfony/config": "^3.4|^4", - "symfony/http-kernel": "^3.4|^4", - "symfony/filesystem": "^3.4|^4", + "symfony/dependency-injection": "^3.4|^4|^5", + "symfony/config": "^3.4|^4|^5", + "symfony/http-kernel": "^3.4|^4|^5", + "symfony/filesystem": "^3.4|^4|^5", "enqueue/null": "0.9.x-dev", "enqueue/fs": "0.9.x-dev", "enqueue/test": "0.9.x-dev" @@ -30,7 +30,7 @@ "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, "suggest": { - "symfony/dependency-injection": "^3.4|^4 If you'd like to use async event dispatcher container extension." + "symfony/dependency-injection": "^3.4|^4|^5 If you'd like to use async event dispatcher container extension." }, "autoload": { "psr-4": { "Enqueue\\AsyncCommand\\": "" }, From 53f181e896b30af441acebe89fde12d5a34f3fcd Mon Sep 17 00:00:00 2001 From: Mathieu Lemoine Date: Wed, 11 Dec 2019 16:32:12 +0100 Subject: [PATCH 24/38] Reduced dependency to voryx/Thruway --- RunCommandProcessor.php | 23 ++++++++++------------- composer.json | 3 ++- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/RunCommandProcessor.php b/RunCommandProcessor.php index f1495f3..2c4462f 100644 --- a/RunCommandProcessor.php +++ b/RunCommandProcessor.php @@ -34,7 +34,11 @@ public function process(Message $message, Context $context): Result $phpBin = (new PhpExecutableFinder())->find(); $consoleBin = file_exists($this->projectDir.'/bin/console') ? './bin/console' : './app/console'; - $process = new Process($phpBin.' '.$consoleBin.' '.$this->getCommandLine($command), $this->projectDir); + $process = new Process(array_merge( + [$phpBin, $consoleBin, $command->getCommand()], + $command->getArguments(), + $this->getCommandLineOptions($command) + ), $this->projectDir); $process->setTimeout($this->timeout); $process->run(); @@ -48,22 +52,15 @@ public function process(Message $message, Context $context): Result } /** - * @return string + * @return string[] */ - private function getCommandLine(RunCommand $command): string + private function getCommandLineOptions(RunCommand $command): array { - $optionsString = ''; + $options = []; foreach ($command->getOptions() as $name => $value) { - $optionsString .= " $name=$value"; + $options[] = "$name=$value"; } - $optionsString = trim($optionsString); - $argumentsString = ''; - foreach ($command->getArguments() as $value) { - $argumentsString .= " $value"; - } - $argumentsString = trim($argumentsString); - - return trim($command->getCommand().' '.$argumentsString.' '.$optionsString); + return $options; } } diff --git a/composer.json b/composer.json index b4e4d90..e886a0c 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,12 @@ "symfony/process": "^3.4|^4|^5" }, "require-dev": { - "phpunit/phpunit": "~5.5", + "phpunit/phpunit": "~7.5", "symfony/dependency-injection": "^3.4|^4|^5", "symfony/config": "^3.4|^4|^5", "symfony/http-kernel": "^3.4|^4|^5", "symfony/filesystem": "^3.4|^4|^5", + "symfony/yaml": "^3.4|^4|^5", "enqueue/null": "0.9.x-dev", "enqueue/fs": "0.9.x-dev", "enqueue/test": "0.9.x-dev" From 15dcd8dd016ccf8c90c12d8e9d15764f89bf8668 Mon Sep 17 00:00:00 2001 From: Mathieu Lemoine Date: Thu, 12 Dec 2019 11:56:38 +0100 Subject: [PATCH 25/38] drop support for Symfony < 4.3 --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index e886a0c..0273ecb 100644 --- a/composer.json +++ b/composer.json @@ -9,16 +9,16 @@ "php": ">=7.1", "enqueue/enqueue": "^0.9", "queue-interop/queue-interop": "^0.7|^0.8", - "symfony/console": "^3.4|^4|^5", - "symfony/process": "^3.4|^4|^5" + "symfony/console": "^4.3|^5", + "symfony/process": "^4.3|^5" }, "require-dev": { "phpunit/phpunit": "~7.5", - "symfony/dependency-injection": "^3.4|^4|^5", - "symfony/config": "^3.4|^4|^5", - "symfony/http-kernel": "^3.4|^4|^5", - "symfony/filesystem": "^3.4|^4|^5", - "symfony/yaml": "^3.4|^4|^5", + "symfony/dependency-injection": "^4.3|^5", + "symfony/config": "^4.3|^5", + "symfony/http-kernel": "^4.3|^5", + "symfony/filesystem": "^4.3|^5", + "symfony/yaml": "^4.3|^5", "enqueue/null": "0.9.x-dev", "enqueue/fs": "0.9.x-dev", "enqueue/test": "0.9.x-dev" @@ -31,7 +31,7 @@ "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, "suggest": { - "symfony/dependency-injection": "^3.4|^4|^5 If you'd like to use async event dispatcher container extension." + "symfony/dependency-injection": "^4.3|^5 If you'd like to use async event dispatcher container extension." }, "autoload": { "psr-4": { "Enqueue\\AsyncCommand\\": "" }, From 5cd2a490d906f18356c09b7bb3a9805b7dfc6fcb Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Thu, 19 Dec 2019 09:01:09 +0200 Subject: [PATCH 26/38] master is 0.10 --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 0273ecb..a511f8b 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,8 @@ "license": "MIT", "require": { "php": ">=7.1", - "enqueue/enqueue": "^0.9", - "queue-interop/queue-interop": "^0.7|^0.8", + "enqueue/enqueue": "^0.10", + "queue-interop/queue-interop": "^0.8", "symfony/console": "^4.3|^5", "symfony/process": "^4.3|^5" }, @@ -19,9 +19,9 @@ "symfony/http-kernel": "^4.3|^5", "symfony/filesystem": "^4.3|^5", "symfony/yaml": "^4.3|^5", - "enqueue/null": "0.9.x-dev", - "enqueue/fs": "0.9.x-dev", - "enqueue/test": "0.9.x-dev" + "enqueue/null": "0.10.x-dev", + "enqueue/fs": "0.10.x-dev", + "enqueue/test": "0.10.x-dev" }, "support": { "email": "opensource@forma-pro.com", @@ -41,7 +41,7 @@ }, "extra": { "branch-alias": { - "dev-master": "0.9.x-dev" + "dev-master": "0.10.x-dev" } } } From 7810b030b2f5a6669d8e437ed79520ca93ac22e5 Mon Sep 17 00:00:00 2001 From: Witold Wasiczko Date: Thu, 30 Jul 2020 20:38:01 +0200 Subject: [PATCH 27/38] Add php 7.3 and 7.4 travis env to test --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9ed4fa1..ae8b10d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ language: php php: - '7.1' - '7.2' + - '7.3' + - '7.4' cache: directories: From 90938715d6b2f38dd717ecc87615b429d4141bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20CROMBEZ?= <777666+jcrombez@users.noreply.github.com> Date: Mon, 24 Aug 2020 16:28:11 +0200 Subject: [PATCH 28/38] [async-command] Fix service definition to apply the timeout addArgument add only one argument at a time to the construtor, right now the timeout configured by the user is never applied and it's always the default (60) value, this fixes it. --- DependencyInjection/AsyncCommandExtension.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/AsyncCommandExtension.php b/DependencyInjection/AsyncCommandExtension.php index d1f4157..c1a0fa8 100644 --- a/DependencyInjection/AsyncCommandExtension.php +++ b/DependencyInjection/AsyncCommandExtension.php @@ -24,7 +24,8 @@ public function load(array $configs, ContainerBuilder $container) $id = sprintf('enqueue.async_command.%s.run_command_processor', $client['name']); $container->register($id, RunCommandProcessor::class) - ->addArgument('%kernel.project_dir%', $client['timeout']) + ->addArgument('%kernel.project_dir%') + ->addArgument($client['timeout']) ->addTag('enqueue.processor', [ 'client' => $client['name'], 'command' => $client['command_name'] ?? Commands::RUN_COMMAND, From f8c12a2b91e146381b1a938261b7c1b4b7f6bbb6 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Sun, 24 Jan 2021 20:45:22 +0200 Subject: [PATCH 29/38] Fix more attributes; nullable params --- Tests/RunCommandProcessorTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/RunCommandProcessorTest.php b/Tests/RunCommandProcessorTest.php index 3065ec3..7a7a364 100644 --- a/Tests/RunCommandProcessorTest.php +++ b/Tests/RunCommandProcessorTest.php @@ -3,11 +3,14 @@ namespace Enqueue\AsyncCommand\Tests; use Enqueue\AsyncCommand\RunCommandProcessor; +use Enqueue\Test\ReadAttributeTrait; use Interop\Queue\Processor; use PHPUnit\Framework\TestCase; class RunCommandProcessorTest extends TestCase { + use ReadAttributeTrait; + public function testShouldImplementProcessorInterface() { $rc = new \ReflectionClass(RunCommandProcessor::class); From 4dbeaa7ba4c8dc178453f990473cca4f6a2fae63 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Mon, 25 Jan 2021 09:51:30 +0200 Subject: [PATCH 30/38] Update PHP and PHPUnit across all packages; fix ext-rdkafka requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a511f8b..24a24e8 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "symfony/process": "^4.3|^5" }, "require-dev": { - "phpunit/phpunit": "~7.5", + "phpunit/phpunit": "^9.5", "symfony/dependency-injection": "^4.3|^5", "symfony/config": "^4.3|^5", "symfony/http-kernel": "^4.3|^5", From c3a74a231fe7cceae5524b432d6a6f3e8a7f65b2 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Tue, 9 Feb 2021 02:14:42 +0200 Subject: [PATCH 31/38] Fix package CI - Add push to master trigger; - Replace the clunky cache + composer install steps with an Action; - Replace Travis with GH WF in packages; - Add the missing CI to amqp-tools; - Replace the shields. --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ .travis.yml | 23 ----------------------- README.md | 2 +- 3 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e60e63b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI +on: + pull_request: + push: + branches: + - master +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ['7.3', '7.4'] + + name: PHP ${{ matrix.php }} tests + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - uses: "ramsey/composer-install@v1" + with: + composer-options: "--prefer-source" + + - run: vendor/bin/phpunit --exclude-group=functional diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ae8b10d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -sudo: false - -git: - depth: 10 - -language: php - -php: - - '7.1' - - '7.2' - - '7.3' - - '7.4' - -cache: - directories: - - $HOME/.composer/cache - -install: - - composer self-update - - composer install --prefer-source - -script: - - vendor/bin/phpunit --exclude-group=functional diff --git a/README.md b/README.md index bd89567..cb6eef5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Enqueue is an MIT-licensed open source project with its ongoing development made # Symfony Async Command. [![Gitter](https://badges.gitter.im/php-enqueue/Lobby.svg)](https://gitter.im/php-enqueue/Lobby) -[![Build Status](https://travis-ci.org/php-enqueue/async-command.png?branch=master)](https://travis-ci.org/php-enqueue/async-command) +[![Build Status](https://img.shields.io/github/workflow/status/php-enqueue/async-command/CI)](https://github.com/php-enqueue/async-command/actions?query=workflow%3ACI) [![Total Downloads](https://poser.pugx.org/enqueue/async-command/d/total.png)](https://packagist.org/packages/enqueue/async-command) [![Latest Stable Version](https://poser.pugx.org/enqueue/async-command/version.png)](https://packagist.org/packages/enqueue/async-command) From ff043e0dc981831dbe11f4ba46ebbcea3ecce3f6 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Tue, 9 Feb 2021 14:01:28 +0200 Subject: [PATCH 32/38] Add php 8 to packages' build matrices; normalize composer reqs --- .github/workflows/ci.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e60e63b..a168dca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.3', '7.4'] + php: ['7.3', '7.4', '8.0'] name: PHP ${{ matrix.php }} tests diff --git a/composer.json b/composer.json index 24a24e8..4317d1e 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "https://enqueue.forma-pro.com/", "license": "MIT", "require": { - "php": ">=7.1", + "php": "^7.3|^8.0", "enqueue/enqueue": "^0.10", "queue-interop/queue-interop": "^0.8", "symfony/console": "^4.3|^5", From 22ea0a7fbf41013b642cb783af800bdb79cc9548 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Thu, 10 Feb 2022 18:49:44 +0200 Subject: [PATCH 33/38] Add support for Symfony 6 --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 4317d1e..932499e 100644 --- a/composer.json +++ b/composer.json @@ -9,16 +9,16 @@ "php": "^7.3|^8.0", "enqueue/enqueue": "^0.10", "queue-interop/queue-interop": "^0.8", - "symfony/console": "^4.3|^5", - "symfony/process": "^4.3|^5" + "symfony/console": "^4.3|^5|^6.0", + "symfony/process": "^4.3|^5|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/dependency-injection": "^4.3|^5", - "symfony/config": "^4.3|^5", - "symfony/http-kernel": "^4.3|^5", - "symfony/filesystem": "^4.3|^5", - "symfony/yaml": "^4.3|^5", + "symfony/dependency-injection": "^4.3|^5|^6.0", + "symfony/config": "^4.3|^5|^6.0", + "symfony/http-kernel": "^4.3|^5|^6.0", + "symfony/filesystem": "^4.3|^5|^6.0", + "symfony/yaml": "^4.3|^5|^6.0", "enqueue/null": "0.10.x-dev", "enqueue/fs": "0.10.x-dev", "enqueue/test": "0.10.x-dev" @@ -31,7 +31,7 @@ "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, "suggest": { - "symfony/dependency-injection": "^4.3|^5 If you'd like to use async event dispatcher container extension." + "symfony/dependency-injection": "^4.3|^5|^6.0 If you'd like to use async event dispatcher container extension." }, "autoload": { "psr-4": { "Enqueue\\AsyncCommand\\": "" }, From c3ad376f095d2d0a27bfad682d470f93e5563329 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Wed, 16 Feb 2022 13:14:49 +0200 Subject: [PATCH 34/38] =?UTF-8?q?Drop=20Symfony=20<=205.1=20=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 932499e..98b90ad 100644 --- a/composer.json +++ b/composer.json @@ -9,16 +9,16 @@ "php": "^7.3|^8.0", "enqueue/enqueue": "^0.10", "queue-interop/queue-interop": "^0.8", - "symfony/console": "^4.3|^5|^6.0", - "symfony/process": "^4.3|^5|^6.0" + "symfony/console": "^5.1|^6.0", + "symfony/process": "^5.1|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/dependency-injection": "^4.3|^5|^6.0", - "symfony/config": "^4.3|^5|^6.0", - "symfony/http-kernel": "^4.3|^5|^6.0", - "symfony/filesystem": "^4.3|^5|^6.0", - "symfony/yaml": "^4.3|^5|^6.0", + "symfony/dependency-injection": "^5.1|^6.0", + "symfony/config": "^5.1|^6.0", + "symfony/http-kernel": "^5.1|^6.0", + "symfony/filesystem": "^5.1|^6.0", + "symfony/yaml": "^5.1|^6.0", "enqueue/null": "0.10.x-dev", "enqueue/fs": "0.10.x-dev", "enqueue/test": "0.10.x-dev" @@ -31,7 +31,7 @@ "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, "suggest": { - "symfony/dependency-injection": "^4.3|^5|^6.0 If you'd like to use async event dispatcher container extension." + "symfony/dependency-injection": "^5.1|^6.0 If you'd like to use async event dispatcher container extension." }, "autoload": { "psr-4": { "Enqueue\\AsyncCommand\\": "" }, From 5ee8c6133d80ce7b3dc67f459401dfd70b02c009 Mon Sep 17 00:00:00 2001 From: Alex Mayer Date: Sat, 25 Feb 2023 22:18:02 -0500 Subject: [PATCH 35/38] Fix Shield URLs in READMEs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb6eef5..711e971 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Enqueue is an MIT-licensed open source project with its ongoing development made # Symfony Async Command. [![Gitter](https://badges.gitter.im/php-enqueue/Lobby.svg)](https://gitter.im/php-enqueue/Lobby) -[![Build Status](https://img.shields.io/github/workflow/status/php-enqueue/async-command/CI)](https://github.com/php-enqueue/async-command/actions?query=workflow%3ACI) +[![Build Status](https://img.shields.io/github/actions/workflow/status/php-enqueue/async-command/ci.yml?branch=master)](https://github.com/php-enqueue/async-command/actions?query=workflow%3ACI) [![Total Downloads](https://poser.pugx.org/enqueue/async-command/d/total.png)](https://packagist.org/packages/enqueue/async-command) [![Latest Stable Version](https://poser.pugx.org/enqueue/async-command/version.png)](https://packagist.org/packages/enqueue/async-command) From 4822bbe1b450abdc172f6c18866bce932aece185 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Sun, 19 Feb 2023 15:13:41 +0200 Subject: [PATCH 36/38] Properly drop old PHP and Symfony versions --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 98b90ad..48fd6f0 100644 --- a/composer.json +++ b/composer.json @@ -6,19 +6,19 @@ "homepage": "https://enqueue.forma-pro.com/", "license": "MIT", "require": { - "php": "^7.3|^8.0", + "php": "^7.4|^8.0", "enqueue/enqueue": "^0.10", "queue-interop/queue-interop": "^0.8", - "symfony/console": "^5.1|^6.0", - "symfony/process": "^5.1|^6.0" + "symfony/console": "^5.4|^6.0", + "symfony/process": "^5.4|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/dependency-injection": "^5.1|^6.0", - "symfony/config": "^5.1|^6.0", - "symfony/http-kernel": "^5.1|^6.0", - "symfony/filesystem": "^5.1|^6.0", - "symfony/yaml": "^5.1|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/config": "^5.4|^6.0", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/filesystem": "^5.4|^6.0", + "symfony/yaml": "^5.4|^6.0", "enqueue/null": "0.10.x-dev", "enqueue/fs": "0.10.x-dev", "enqueue/test": "0.10.x-dev" @@ -31,7 +31,7 @@ "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, "suggest": { - "symfony/dependency-injection": "^5.1|^6.0 If you'd like to use async event dispatcher container extension." + "symfony/dependency-injection": "^5.4|^6.0 If you'd like to use async event dispatcher container extension." }, "autoload": { "psr-4": { "Enqueue\\AsyncCommand\\": "" }, From 3b6e9329d58d8cf236296629723f9f5ed2b99102 Mon Sep 17 00:00:00 2001 From: Witold Wasiczko Date: Thu, 23 Mar 2023 10:50:55 +0100 Subject: [PATCH 37/38] Update and fix pkg test with 8.1 and 8.2 PHP support --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a168dca..0492424 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.3', '7.4', '8.0'] + php: ['7.4', '8.0', '8.1', '8.2'] name: PHP ${{ matrix.php }} tests From 8db7bf16f8cdac8f290671c52dddc60ead1ed155 Mon Sep 17 00:00:00 2001 From: James Read Date: Wed, 15 Jan 2025 22:51:32 +0000 Subject: [PATCH 38/38] Running php-cs-fixer Running php-cs-fixer to fix CS drift --- CommandResult.php | 13 ++----------- Commands.php | 2 +- RunCommand.php | 9 ++------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/CommandResult.php b/CommandResult.php index 1c746a9..10080d5 100644 --- a/CommandResult.php +++ b/CommandResult.php @@ -19,11 +19,6 @@ final class CommandResult implements \JsonSerializable */ private $errorOutput; - /** - * @param int $exitCode - * @param string $output - * @param string $errorOutput - */ public function __construct(int $exitCode, string $output, string $errorOutput) { $this->exitCode = $exitCode; @@ -58,12 +53,8 @@ public function jsonSerialize(): array public static function jsonUnserialize(string $json): self { $data = json_decode($json, true); - if (JSON_ERROR_NONE !== json_last_error()) { - throw new \InvalidArgumentException(sprintf( - 'The malformed json given. Error %s and message %s', - json_last_error(), - json_last_error_msg() - )); + if (\JSON_ERROR_NONE !== json_last_error()) { + throw new \InvalidArgumentException(sprintf('The malformed json given. Error %s and message %s', json_last_error(), json_last_error_msg())); } return new self($data['exitCode'], $data['output'], $data['errorOutput']); diff --git a/Commands.php b/Commands.php index 0d751ac..abc015c 100644 --- a/Commands.php +++ b/Commands.php @@ -4,5 +4,5 @@ final class Commands { - const RUN_COMMAND = 'run_command'; + public const RUN_COMMAND = 'run_command'; } diff --git a/RunCommand.php b/RunCommand.php index 437c3a6..573a620 100644 --- a/RunCommand.php +++ b/RunCommand.php @@ -20,7 +20,6 @@ final class RunCommand implements \JsonSerializable private $options; /** - * @param string $command * @param string[] $arguments * @param string[] $options */ @@ -64,12 +63,8 @@ public function jsonSerialize(): array public static function jsonUnserialize(string $json): self { $data = json_decode($json, true); - if (JSON_ERROR_NONE !== json_last_error()) { - throw new \InvalidArgumentException(sprintf( - 'The malformed json given. Error %s and message %s', - json_last_error(), - json_last_error_msg() - )); + if (\JSON_ERROR_NONE !== json_last_error()) { + throw new \InvalidArgumentException(sprintf('The malformed json given. Error %s and message %s', json_last_error(), json_last_error_msg())); } return new self($data['command'], $data['arguments'], $data['options']);