Batch API drush command running once then shows Solr error

I am trying to create a drush command to run a batch process. When I run the command, the batch runs just once, and I get this error :

in Drupalsearch_api_solrSolrConnectorSolrConnectorPluginBase->handleHttpException() (line 1026 of /var/www/html/web/modules/contrib/search_api_solr/src/SolrConnector/SolrConnectorPluginBase.php). Drupalsearch_api_solrSearchApiSolrException: Solr endpoint http://solr:8983/ not found (code: 404

This is my code, am I doing something wrong? Thanks for your help:

class Drush9CustomCommands extends DrushCommands {    use StringTranslationTrait;   private $entityTypeManager;   protected $logger;   protected $batchService;      public function __construct(EntityTypeManagerInterface $entityTypeManager, LoggerInterface $logger, BatchService $batch_service) {     parent::__construct();     $this->entityTypeManager = $entityTypeManager;     $this->logger = $logger;     $this->batchService = $batch_service;   }    /**    * Update Node.    *    * @command update:node    * @aliases update-node    *    * @usage update:node foo    *   foo is the type of node to update    */   public function updateNode() {      $batch = array(       'title' => t('Exporting'),       'operations' => array(         array([$this->batchService,'processMyNode'], array()),       ),       'finished' => [$this->batchService,'processMyNodeFinished'],     );     batch_set($batch);      drush_backend_batch_process();   } } 

Batchservice.php

class BatchService implements ContainerInjectionInterface {    use StringTranslationTrait;   protected $messenger;    public function __construct(MessengerInterface $messenger) {     $this->messenger = $messenger;   }    /**    * {@inheritDoc}    */   public static function create(ContainerInterface $container) {     return new static(       $container->get('messenger')     );   }    /**    * Batch process callback.    *    * @param int $id    *   Id of the batch.    * @param string $operation_details    *   Details of the operation.    * @param object $context    *   Context for operations.    */   public function processMyNode( &$context) {     if (!isset($context['sandbox']['total'])) {       // Get node experience ids.       $query = Drupal::entityTypeManager()->getStorage('node')->getQuery();       $nids = $query         ->condition('type', 'mynode')         ->range(0,1000)         ->accessCheck(FALSE)         ->execute();        $context['sandbox']['total'] = count($nids);       $context['sandbox']['node_ids'] = $nids;       $context['sandbox']['current'] = 0;     }     $node_ids = array_slice($context['sandbox']['node_ids'], $context['sandbox']['current'], 25);      foreach ($node_ids as $nid) {       $node = Drupal::entityTypeManager()->getStorage('node')->load($nid);       $node->set('field_my_field', 'my field value');       $node->save();     }      $context['sandbox']['current'] += count($node_ids);      Drupal::logger('test')->notice($context['sandbox']['current'] . ' Experiences passed / ' . $context['sandbox']['total']);      if ($context['sandbox']['total'] == 0) {       $context['sandbox']['#finished'] = 1;     }     else {        $context['sandbox']['#finished'] = ($context['sandbox']['current'] / $context['sandbox']['total']);     }   }    /**    * Batch Finished callback.    *    * @param bool $success    *   Success of the operation.    * @param array $results    *   Array of results for post processing.    * @param array $operations    *   Array of operations.    */   public  function processMyNodeFinished($success, array $results, array $operations) {      if ($success) {       $message = Drupal::translation()->formatPlural(count($results), 'One post processed.', '@count posts processed.');     }     else {       $message = t('Finished with an error.');     }     Drupal::logger('teset')->notice($message);   }  } 
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Batch API drush command running once then shows Solr error

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.