QueueLoop.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Cron;
  3. use ModulesGarden\ProxmoxAddon\Core\CommandLine\CommandLoop;
  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. class QueueLoop extends CommandLoop
  10. {
  11. /**
  12. * Command name
  13. * @var string
  14. */
  15. protected $name = 'queue-loop';
  16. /**
  17. * Command description
  18. * @var string
  19. */
  20. protected $description = 'Run module queue loop';
  21. /**
  22. * Command help text
  23. * @var string
  24. */
  25. protected $help = 'Just run that command to start all queued tasks!';
  26. protected function process(InputInterface $input, OutputInterface $output, SymfonyStyle $io)
  27. {
  28. $queue = new \ModulesGarden\ProxmoxAddon\Core\Queue\Queue();
  29. $queue->setCallBefore(function (Job $job) use ($input,$io)
  30. {
  31. $io->writeln("Running {$job->job}");
  32. (new Hypervisor($this->getName(), $input->getOptions()))
  33. ->ping();
  34. });
  35. $queue->process();
  36. }
  37. }