ProcessPlatformEvents.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Cron;
  6. use Temando\Shipping\Model\Config\ModuleConfig;
  7. use Temando\Shipping\Sync\EventStreamProcessor;
  8. /**
  9. * Process events as dispatched by the Temando platform.
  10. *
  11. * The Temando Shipping module is one out of many applications that handle the
  12. * merchant's entities at the platform. If another application (ERP, WMS, etc.)
  13. * edits entities at the platform, the M2 instance will be notified and the
  14. * local counterpart will be updated accordingly.
  15. *
  16. * @package Temando\Shipping\Cron
  17. * @author Benjamin Heuer <benjamin.heuer@netresearch.de>
  18. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. * @link http://www.temando.com/
  20. */
  21. class ProcessPlatformEvents
  22. {
  23. /**
  24. * @var EventStreamProcessor
  25. */
  26. private $processor;
  27. /**
  28. * @var ModuleConfig
  29. */
  30. private $moduleConfig;
  31. /**
  32. * @param EventStreamProcessor $processor
  33. * @param ModuleConfig $moduleConfig
  34. */
  35. public function __construct(EventStreamProcessor $processor, ModuleConfig $moduleConfig)
  36. {
  37. $this->processor = $processor;
  38. $this->moduleConfig = $moduleConfig;
  39. }
  40. /**
  41. * Run cron if it is enabled via module config.
  42. *
  43. * @return void
  44. */
  45. public function execute()
  46. {
  47. if ($this->moduleConfig->isSyncEnabled()) {
  48. $this->processor->processEvents(100);
  49. }
  50. }
  51. }