/** * @param Store $store * @param Action $action * @throws StoreNotRunnableException */ protected function runStore($store, $action) { $this->logger->debug(" -> going to run store " . $store->getName()); $runner = $this->container->get($store->getService(), ContainerInterface::NULL_ON_INVALID_REFERENCE); if (!isset($runner)) { throw new StoreNotRunnableException("Store " . $store->getName() . " is not runnable : service with name '" . $store->getService() . "' does not exist'"); } if (!$runner instanceof RunnableStore) { throw new StoreNotRunnableException("Service '" . $store->getService() . '\' does not implement \\Wizbii\\PipelineBundle\\Runnable\\Store interface'); } try { $start = microtime(true); $eventsGenerator = $runner->run($action); $stop = microtime(true); $this->logger->info("[" . getmypid() . "]" . " Service " . $store->getService() . " tooked " . ($stop - $start) . " to process " . $action->getName()); if ($store->hasTriggeredEvent() && isset($eventsGenerator)) { foreach ($eventsGenerator->produce() as $dataBag) { $this->eventDispatcher->dispatch($store->getTriggeredEvent()->getName(), $dataBag->all()); } } } catch (\Exception $e) { $this->logger->warning("Store " . $store->getName() . " has thrown an exception. Message was : " . $e->getMessage() . ". It occurs at " . $e->getFile() . ":" . $e->getLine()); } // run next stores foreach ($this->pipelineProvider->getCurrentPipeline()->getStores() as $anotherStore) { if ($anotherStore->isTriggeredByStore($store)) { $this->runStore($anotherStore, $action); } } }
/** * @param Store $store */ public function addStore($store) { $this->stores[$store->getName()] = $store; }