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\Task
s 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...
addIndex
updateIndex
removeIndex
deleteItems
deleteAllIndexItems
Note that I'm considering the following out-of-scope, but I might file follow-up issues...
- 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);
- 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
- Write a patch
- Review and feedback
- RTBC and feedback
- Commit
- Release