JobsLoop.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\CommandLine;
  3. use ModulesGarden\ProxmoxAddon\Core\CommandLine\AbstractCommand;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputOption;
  6. class JobsLoop extends AbstractCommand
  7. {
  8. /**
  9. * Loop interval in seconds
  10. * @var int
  11. */
  12. protected $loopInterval = 5;
  13. /**
  14. * @var int
  15. */
  16. protected $maxChildren = 5;
  17. /**
  18. * @var int
  19. */
  20. protected $tasksPerChildren = 10;
  21. /**
  22. *
  23. */
  24. final protected function configure()
  25. {
  26. parent::configure();
  27. }
  28. /**
  29. *
  30. */
  31. final protected function setup()
  32. {
  33. $this->addOption('parent', InputOption::VALUE_OPTIONAL, 'Parent id', null);
  34. $this->addOption('id', InputOption::VALUE_OPTIONAL, 'Child id', null);
  35. }
  36. /**
  37. * Execute command in the loop
  38. * @param InputInterface $input
  39. * @param OutputInterface $output
  40. */
  41. final protected function execute(InputInterface $input, OutputInterface $output)
  42. {
  43. $parent = $input->getOption('parent');
  44. $id = $input->getOption('id');
  45. $parentHypervior = new Hypervisor($this->getName());
  46. //Lock parent
  47. if (!$parent)
  48. {
  49. $parentHypervior->lock();
  50. }
  51. else
  52. {
  53. $parentHypervior->checkIfRunning();
  54. }
  55. if ($id)
  56. {
  57. }
  58. do
  59. {
  60. parent::process($input, $output, new SymfonyStyle($input, $output));
  61. sleep($this->loopInterval);
  62. }
  63. while (!$hypervisor->isStopped());
  64. }
  65. /**
  66. * @param $jobs[]
  67. */
  68. protected function processJobs($jobs)
  69. {
  70. foreach ($jobs as $job)
  71. {
  72. }
  73. }
  74. }