Queue.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Cron;
  3. use ModulesGarden\ProxmoxAddon\Core\CommandLine\AbstractCommand;
  4. use ModulesGarden\ProxmoxAddon\Core\CommandLine\Hypervisor;
  5. use ModulesGarden\ProxmoxAddon\Core\Queue\Models\Job;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Symfony\Component\Console\Style\SymfonyStyle;
  9. /**
  10. * Class Queue
  11. * @package ModulesGarden\ProxmoxAddon\App\Cron
  12. */
  13. class Queue extends AbstractCommand
  14. {
  15. /**
  16. * Command name
  17. * @var string
  18. */
  19. protected $name = 'queue';
  20. /**
  21. * Command description
  22. * @var string
  23. */
  24. protected $description = 'Run module queue';
  25. /**
  26. * Command help text
  27. * @var string
  28. */
  29. protected $help = 'Just run that command to start all queued tasks!';
  30. /**
  31. * Configure command
  32. */
  33. protected function setup()
  34. {
  35. }
  36. /**
  37. * Run your custom code
  38. * @param InputInterface $input
  39. * @param OutputInterface $output
  40. * @return int|null|void
  41. */
  42. protected function process(InputInterface $input, OutputInterface $output, SymfonyStyle $io)
  43. {
  44. $queue = new \ModulesGarden\ProxmoxAddon\Core\Queue\Queue();
  45. $queue->setCallBefore(function (Job $job) use ($input,$io)
  46. {
  47. $io->writeln("Running {$job->job}");
  48. (new Hypervisor($this->getName(), $input->getOptions()))
  49. ->ping();
  50. });
  51. $queue->process();
  52. }
  53. }