The "advancedqueue_job_type" entity type does not exist.

Created on 23 June 2023, about 1 year ago

Problem/Motivation

On two sites now, I've tried to add items to a queue using a jobtype I created, and I get this error:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "advancedqueue_job_type" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).

I am at my wits end as I can find no reference to advancedqueue_job_type anywhere.

Steps to reproduce

I installed Advanced Queue.

Created a new queue, "BatchEmbed", machine name "batchembed".

Created a job type:

/src/Plugin/AdvancedQueue/JobType/SolraiAdvancedQueue.php

This is the code:


namespace Drupal\solrai\Plugin\AdvancedQueue\JobType;

use Drupal\advancedqueue\Job;
use Drupal\advancedqueue\JobResult;
use Drupal\advancedqueue\Plugin\AdvancedQueue\JobType\JobTypeBase;
use Drupal\solrai\SolraiEmbedService;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides a job type for embedding Solrai content.
 *
 * @AdvancedQueueJobType(
 *   id = "solrai_advanced_queue",
 *   label = @Translation("Solrai advanced queue"),
 * )
 */
class SolraiAdvancedQueue extends JobTypeBase {

  /**
   * The SolraiEmbedService.
   *
   * @var \Drupal\solrai\SolraiEmbedService
   */
  protected $solraiEmbedService;

  /**
   * Constructs a new SolraiEmbedSingle.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\solrai\SolraiEmbedService $solrai_embed_service
   *   The SolraiEmbedService.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, SolraiEmbedService $solrai_embed_service) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->solraiEmbedService = $solrai_embed_service;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('solrai.embed_service')
    );
  }


  /**
   * {@inheritdoc}
   */
	public function process(Job $job) {
		$payload = $job->getPayload();
		
		// Call the solrai_embedSingle() method.
		$result = $this->solraiEmbedService->solrai_embedSingle(
		  $payload['solrPrompt'],
		  $payload['sortField'],
		  $payload['rows'],
		  $payload['start'],
		  $payload['forceUpdate'],
		  $payload['summarize'],
		  $payload['questionsOn']
		);

		// Check the result for the error phrase.
		if (strpos($result, 'ERROR:') !== false) {
		  // An error occurred, return a failure result with the method output.
		  return JobResult::failure($result);
		}

		// No error detected, return a successful result.
		return JobResult::success();
	}

}

In the class method which is attempting to add the queue item, I configure the payload and queue:

			$payload = [
			  'solrPrompt' => $solrPrompt,
			  'sortField' => $sortField,
			  'rows' => $rows,
			  'start' => $start,
			  'forceUpdate' => $forceUpdate,
			  'summarize' => $summarize,
			  'questionsOn' => $questionsOn
			];

			$queue = \Drupal\advancedqueue\Entity\Queue::load('batchembed');

I then attempt to execute this this:

	$job = \Drupal\advancedqueue\Job::create('solrai_advanced_queue', $payload);
	$queue->enqueueJob($job);

Which results in this error:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "advancedqueue_job_type" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).

Following the only tutorial I was able to find in Advanced Queue, it appears that I have created the job type but Advanced Queue is not recognizing it. As it happens consistently across two sites now, it would appear to be a bug.

Proposed resolution

Help me!!!!

πŸ› Bug report
Status

Fixed

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States SomebodySysop

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @SomebodySysop
  • πŸ‡ΊπŸ‡ΈUnited States SomebodySysop

    Finally figured it out. Not having any assistance other than ChatGPT, I was given this code to check for presence of job type

    Bad

    // Check if the "solrai_advanced_queue" job type exists.
    	   $job_type = \Drupal::entityTypeManager()->getStorage('advancedqueue_job_type')->load('solrai_advanced_queue');
    	   if (!$job_type) {
    		 // If the "solrai_advanced_queue" job type does not exist, return an error message.
    		 return "ERROR: solrai_advanced_queue job type does not exist!";
    	   }
    
    

    Through trial and error, finally lucked up on code that worked.

    Good

    $job_type_manager = \Drupal::service('plugin.manager.advancedqueue_job_type');
    
    if (!$job_type_manager->hasDefinition('solrai_advanced_queue')) {
        // The job type does not exist
        return "ERROR: solrai_advanced_queue job type does not exist!";
    }
    
    

    Again, if there is documentation on this, please give me the link.

  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024