public function run(\GearmanJob $job)
 {
     $url = GearmanToolsUtils::unpackMessage($job->workload());
     $error = 0;
     try {
         $this->processorPool->process($url);
         $extractedUrlsCount = count($this->processorPool->getExtractedUrls());
         $message = "{$url->getUrl()} / depth: {$url->getDepth()} / status: {$url->getStatus()} / extracted: {$extractedUrlsCount}";
     } catch (\Exception $e) {
         $message = "Failed to process url [{$url->getId()}] \"{$url->getUrl()}\": {$e->getMessage()}";
         $error = $e->getCode();
         $error = $error === 0 ? -1 : $error;
     }
     $result = ['url' => $url, 'extractedUrls' => $this->processorPool->getExtractedUrls(), 'error' => $error, 'message' => $message];
     $this->logger->info($message);
     $result = GearmanToolsUtils::packMessage($result);
     return $result;
 }
 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);
 }