| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace ModulesGarden\Servers\ZimbraEmail\Core\CommandLine;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- class CommandLoop extends AbstractCommand
- {
- /**
- * Loop interval in seconds
- * @var int
- */
- protected $loopInterval = 5;
- /**
- * Loop counter
- * @var int
- * @TODO remove me
- */
- private $loopCounter = 0;
- /**
- *
- */
- final protected function configure()
- {
- parent::configure();
- }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int|null|void
- * @throws \Exception
- */
- final protected function execute(InputInterface $input, OutputInterface $output)
- {
- $hypervisor = new Hypervisor($this->getName(), $input->getOptions());
- /**
- * Lock command in database. We want to run only one command in the same time
- */
- $hypervisor->lock();
- do
- {
- /**
- * Let's do something funny!
- */
- parent::execute($input, $output);
- /**
- * Ping... Pong... Ping...
- */
- $hypervisor->ping();
- /**
- * Time to sleep!
- */
- $hypervisor->sleep($this->loopInterval);
- /**
- * @TODO remove me
- */
- $this->loopCounter++;
- }
- while(!$hypervisor->shouldBeStopped());
- /**
- * Unlock command in database
- */
- $hypervisor->unlock();
- }
- /**
- * @return int
- */
- final protected function getLoopCounter()
- {
- return $this->loopCounter;
- }
- }
- //
|