You are here

class TaskEvent in Search API 8

Represents an event that was fired to execute a pending task.

A module receiving and properly handling such an event should call its stopPropagation() method so the task manager will know that it was successfully executed and can be deleted.

If the code handling the task wants to flag an error during execution, it should set an exception on the task.

Hierarchy

  • class \Drupal\search_api\Task\TaskEvent extends \Symfony\Component\EventDispatcher\Event

Expanded class hierarchy of TaskEvent

2 files declare their use of TaskEvent
ContentEntityTaskManager.php in src/Plugin/search_api/datasource/ContentEntityTaskManager.php
TestTaskWorker.php in tests/search_api_test_tasks/src/TestTaskWorker.php

File

src/Task/TaskEvent.php, line 18

Namespace

Drupal\search_api\Task
View source
class TaskEvent extends Event {

  /**
   * The task being executed.
   *
   * @var \Drupal\search_api\Task\TaskInterface
   */
  protected $task;

  /**
   * The exception that stopped execution of the task, if any.
   *
   * @var \Drupal\search_api\SearchApiException|null
   */
  protected $exception;

  /**
   * Constructs a TaskEvent object.
   *
   * @param \Drupal\search_api\Task\TaskInterface $task
   *   The task being executed.
   */
  public function __construct(TaskInterface $task) {
    $this->task = $task;
  }

  /**
   * Retrieves the executed task.
   *
   * @return \Drupal\search_api\Task\TaskInterface
   *   The task being executed.
   */
  public function getTask() {
    return $this->task;
  }

  /**
   * Retrieves any exception that stopped the execution of the task.
   *
   * @return \Drupal\search_api\SearchApiException|null
   *   The exception, if any.
   */
  public function getException() {
    return $this->exception;
  }

  /**
   * Sets the exception that stopped the execution of the task.
   *
   * @param \Drupal\search_api\SearchApiException|null $exception
   *   The exception that occurred.
   *
   * @return $this
   */
  public function setException(SearchApiException $exception = NULL) {
    $this->exception = $exception;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TaskEvent::$exception protected property The exception that stopped execution of the task, if any.
TaskEvent::$task protected property The task being executed.
TaskEvent::getException public function Retrieves any exception that stopped the execution of the task.
TaskEvent::getTask public function Retrieves the executed task.
TaskEvent::setException public function Sets the exception that stopped the execution of the task.
TaskEvent::__construct public function Constructs a TaskEvent object.