Guest User

Untitled

a guest
Feb 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Service\Queue\Processor;
  4.  
  5. use Enqueue\Client\CommandSubscriberInterface;
  6. use Enqueue\Consumption\Result;
  7. use Interop\Queue\PsrContext;
  8. use Interop\Queue\PsrMessage;
  9. use Interop\Queue\PsrProcessor;
  10. use Symfony\Component\Process\Exception\ProcessFailedException;
  11. use Symfony\Component\Process\Process;
  12.  
  13. class RunCommandProcessor implements PsrProcessor, CommandSubscriberInterface
  14. {
  15. /**
  16. * @var string
  17. */
  18. private $projectDir;
  19.  
  20. public function __construct(string $projectDir)
  21. {
  22. $this->projectDir = $projectDir;
  23. }
  24.  
  25. public function process(PsrMessage $message, PsrContext $context)
  26. {
  27. $commandline = $message->getBody();
  28.  
  29. $process = new Process('./bin/console '.$commandline, $this->projectDir);
  30.  
  31. try {
  32. $process->mustRun();
  33.  
  34. return Result::ACK;
  35. } catch (ProcessFailedException $e) {
  36. return Result::reject(sprintf('The process failed with exception: "%s" in %s at %s', $e->getMessage(), $e->getFile(), $e->getLine()));
  37. }
  38. }
  39.  
  40. public static function getSubscribedCommand()
  41. {
  42. return 'run_command';
  43. }
  44. }
Add Comment
Please, Sign In to add comment