public function run() { while ($url = $this->repository->next()) { try { $this->processorPool->process($url); } catch (\Exception $e) { if ($this->logger) { $this->logger->error("Failed to process url [{$url->getId()}] \"{$url->getUrl()}\": {$e->getMessage()}"); } } foreach ($this->processorPool->getExtractedUrls() as $eu) { $this->repository->insert($eu); } $this->repository->done($url); // log $c = count($this->processorPool->getExtractedUrls()); $this->logger->info("url: {$url->getUrl()} / status: {$url->getStatus()} / extracted: {$c}"); } }
public function _onTask(\GearmanTask $task) { $data = GearmanToolsUtils::unpackMessage($task->data()); $url = $data['url']; $extractedUrls = $data['extractedUrls']; $error = $data['error']; $message = $data['message']; // add extracted url foreach ($extractedUrls as $extractedUrl) { $this->repository->insert($extractedUrl); } // log if ($error === 0) { $this->logger->info($message); } else { $this->logger->error($message); } // mark Url as processed $this->repository->done($url); }