Show which Server Tasks are pending on Server view page

Created on 9 June 2025, about 1 month ago

Problem/Motivation

From time-to-time, a Search API server will end up with some queued Server Tasks. The number of tasks shows up on the Server view page (entity.search_api_server.canonical at /admin/config/search/search-api/server/SERVER_MACHINE_NAME) as follows...

Pending server tasks

There is currently 1 task pending for this server.

Pending tasks are created when operations on the server, such as deleting one or more items, cannot be executed because the server is currently unavailable (which will usually also create an entry in the Drupal logs). They are automatically tried again before any other operation is executed and the operation is aborted if the tasks could still not be executed, or if there are too many pending tasks to be executed in a single page request. In the latter case, you can use this form to manually execute all tasks and thus unblock the server again.

... below this message is an Execute tasks now button. Note this part of the page is built in \Drupal\search_api\Form\ServerStatusForm::buildForm().

However, it doesn't show what Server Tasks are queued, or the order that they're going to be executed in.

User story: As a search administrator or developer, I want to know what tasks are queued, and the order that they will be executed in, so that I can predict problems or debug why the queued tasks are not working.

Steps to reproduce

I'm not sure exactly how to get a server to end up with queued tasks.

Proposed resolution

Update \Drupal\search_api\Task\ServerTaskManager to return an array of pending \Drupal\search_api\Entity\Tasks for a given Server.

Update \Drupal\search_api\Form\ServerStatusForm::buildForm() to show a list of pending task types in order.

In Drush's REPL, the following snippet of code returns a list of pending tasks for a server:

  foreach (\Drupal::service('entity_type.manager')->getStorage('search_api_task')->loadByProperties(['server_id' => 'SERVER_MACHINE_NAME']) as $task) {
  echo $task->getType();
  }

Note that, currently, the task types only have machine names (i.e.: they don't have human-readable labels). Not sure if we want to add human-readable labels...

  1. addIndex
  2. updateIndex
  3. removeIndex
  4. deleteItems
  5. deleteAllIndexItems

Note that I'm considering the following out-of-scope, but I might file follow-up issues...

  1. deleting/clearing tasks
    (i.e.: if I know that a task is not going to work, or will do something that I don't want);
  2. saying that a server does not support certain tasks
    (i.e.: if my organization has only one server, and I need to share that server with other teams, and an administrator and gives me an index on that server to use, the administrator not give Search API permission to addIndex, or removeIndex)

Remaining tasks

  1. Write a patch
  2. Review and feedback
  3. RTBC and feedback
  4. Commit
  5. Release
Feature request
Status

Active

Version

1.0

Component

General code

Created by

🇨🇦Canada mparker17 UTC-4

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024