GearmanCacheWarmupCommand.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Gearman Bundle for Symfony2
  4. *
  5. * @author Marc Morera <yuhu@mmoreram.com>
  6. * @since 2013
  7. */
  8. namespace Mmoreram\GearmanBundle\Command;
  9. use Symfony\Component\Console\Input\InputOption;
  10. use Symfony\Component\Console\Input\InputArgument;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Input\InputDefinition;
  13. use Mmoreram\GearmanBundle\Service\GearmanCache;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Mmoreram\GearmanBundle\Service\GearmanSettings;
  16. use Mmoreram\GearmanBundle\Module\GearmanBaseBundle;
  17. use Mmoreram\GearmanBundle\Service\GearmanCacheLoader;
  18. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  19. /**
  20. * Warm ups all cache data
  21. *
  22. * @author Marc Morera <yuhu@mmoreram.com>
  23. */
  24. class GearmanCacheWarmupCommand extends ContainerAwareCommand
  25. {
  26. /**
  27. * Console Command configuration
  28. */
  29. protected function configure()
  30. {
  31. parent::configure();
  32. $this ->setName('gearman:cache:warmup')
  33. ->setAliases(array('cache:gearman:warmup'))
  34. ->setDescription('Warms up gearman cache data');
  35. }
  36. /**
  37. * Executes the current command.
  38. *
  39. * @param InputInterface $input An InputInterface instance
  40. * @param OutputInterface $output An OutputInterface instance
  41. *
  42. * @return integer 0 if everything went fine, or an error code
  43. *
  44. * @throws \LogicException When this abstract class is not implemented
  45. */
  46. protected function execute(InputInterface $input, OutputInterface $output)
  47. {
  48. $output->writeln('Warming up the cache for the ' . $this->getContainer()->get('kernel')->getEnvironment() . ' environment');
  49. $this
  50. ->getContainer()
  51. ->get('gearman.cache.wrapper')
  52. ->flush()
  53. ->load();
  54. }
  55. }