Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function broadcast(array $channels, $event, array $payload = [])
 {
     $connection = $this->redis->connection($this->connection);
     $payload = json_encode(['event' => $event, 'data' => $payload]);
     foreach ($channels as $channel) {
         $connection->publish($channel, $payload);
     }
 }
Ejemplo n.º 2
0
 /**
  * Broadcast the given event.
  *
  * @param  array  $channels
  * @param  string  $event
  * @param  array  $payload
  * @return void
  */
 public function broadcast(array $channels, $event, array $payload = [])
 {
     $connection = $this->redis->connection($this->connection);
     $socket = Arr::pull($payload, 'socket');
     $payload = json_encode(['event' => $event, 'data' => $payload, 'socket' => $socket]);
     foreach ($this->formatChannels($channels) as $channel) {
         $connection->publish($channel, $payload);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function broadcast(array $channels, $event, array $payload = [])
 {
     $connection = $this->redis->connection($this->connection);
     $data = json_encode(['event' => $event, 'data' => $payload]);
     foreach ($channels as $channel) {
         $subscribers = $connection->publish($channel, $data);
         // Enough subscribers?
         if ($subscribers < $this->minSubscribers) {
             // Add channel
             $data = json_encode(['channel' => $channel, 'event' => $event, 'data' => $payload]);
             // Add to list
             $connection->rpush($this->listName, $data);
         }
     }
 }
Ejemplo n.º 4
0
 protected function publishLinks($urlSet, $count = 0, $deep = true)
 {
     foreach ($urlSet as $set) {
         if ($count >= $this->config->get('settings.publish.limit')) {
             $this->info("* Per-node-link limit reached!");
             break;
         }
         $url = $set['url'];
         $date = $set['lastmod'];
         if ($this->isSitemap($url)) {
             if ($deep) {
                 $count = $this->publishLinks($this->gatherLinks($url), $count, false);
             }
             continue;
         }
         $result = $this->redis->lPush('nodes-queue', json_encode(compact('url', 'date')));
         if ($result > 0) {
             $count++;
             $this->counter['succeeed']++;
         } else {
             $this->counter['failed']++;
         }
     }
     return $count;
 }
Ejemplo n.º 5
0
 /**
  * Sent upstream queue
  * @param int $throttle
  * @return int
  */
 public function sentUpstreamOperations($throttle = 100)
 {
     $chunks = array_chunk($this->operation_queue, $throttle);
     $chunk_count = count($chunks);
     $operations = 0;
     for ($c = 0; $c < $chunk_count; $c++) {
         /** @var \Predis\Pipeline\Pipeline $pipe */
         $pipe = $this->redis->command('pipeline');
         for ($op = count($chunks[$c]); $op > 0; $op--) {
             list($command, $params) = array_shift($chunks[$c]);
             call_user_func_array([$pipe, $command], $params);
             $operations++;
         }
         $pipe->execute();
     }
     $this->operation_queue = [];
     return $operations;
 }
Ejemplo n.º 6
0
 protected function saveNode($title, $content, $url, $date)
 {
     $content = $this->cleanContent($content);
     if (is_null($content)) {
         $this->counter['empty_url']++;
         return false;
     }
     $hashId = md5($url);
     $params = ['index' => 'sites', 'type' => 'default', 'id' => $hashId, 'body' => ['title' => $title, 'content' => $content, 'hash_id' => $hashId, 'date' => $date ? Carbon::createFromTimestamp($date)->toW3cString() : null, 'url' => $url]];
     try {
         $response = $this->client->index($params);
         if (!$response['created']) {
             $this->counter['updated']++;
         } else {
             $this->counter['indexed']++;
         }
     } catch (ElasticsearchException $e) {
         $this->error("# Cannot Index content of {$url}. Check \"failed:{$url}\" key in redis for more information");
         $this->redis->hMSet("failed:{$url}", ['error' => $e->getMessage(), 'params' => $url]);
         $this->counter['failed_index']++;
     }
     return true;
 }
Ejemplo n.º 7
0
 /**
  * Get the Redis connection instance.
  *
  * @return \Predis\ClientInterface
  */
 public function connection()
 {
     return $this->redis->connection($this->connection);
 }
Ejemplo n.º 8
0
 /**
  * Get the connection for the queue.
  *
  * @return \Predis\ClientInterface
  */
 protected function getConnection()
 {
     return $this->redis->connection($this->connection);
 }