You are here

abstract class EdgeJob in Apigee Edge 8

Base class for all Apigee Edge communication jobs.

Hierarchy

  • class \Drupal\apigee_edge\Job\Job
    • class \Drupal\apigee_edge\Job\EdgeJob

Expanded class hierarchy of EdgeJob

File

src/Job/EdgeJob.php, line 27

Namespace

Drupal\apigee_edge\Job
View source
abstract class EdgeJob extends Job {

  /**
   * Request data.
   *
   * @var array
   */
  protected $request;

  /**
   * Response data.
   *
   * @var array
   */
  protected $response;

  /**
   * {@inheritdoc}
   */
  public function execute() : bool {
    $this
      ->executeRequest();
    $journal = $this
      ->getConnector()
      ->getClient()
      ->getJournal();
    $request = $journal
      ->getLastRequest();
    $response = $journal
      ->getLastResponse();
    if (!isset($request) || !isset($response)) {
      return FALSE;
    }
    $this->request = [
      'method' => $request
        ->getMethod(),
      'path' => $request
        ->getUri(),
      'headers' => $request
        ->getHeaders(),
      'body' => $request
        ->getBody()
        ->getContents(),
    ];
    $this->response = [
      'version' => $response
        ->getProtocolVersion(),
      'status' => $response
        ->getStatusCode(),
      'headers' => $response
        ->getHeaders(),
      'body' => $response
        ->getBody()
        ->getContents(),
    ];
    return FALSE;
  }

  /**
   * Returns the SDK connector instance from the global container.
   *
   * The reason why this is not injected, because this class will be serialized,
   * and the service class contains elements that can't be serialized.
   *
   * @return \Drupal\apigee_edge\SDKConnector
   *   The SDK connector service.
   */
  protected function getConnector() : SDKConnectorInterface {
    return \Drupal::service('apigee_edge.sdk_connector');
  }

  /**
   * Executes the request itself.
   */
  protected abstract function executeRequest();

  /**
   * {@inheritdoc}
   */
  public function renderArray() : array {

    // TODO visualize Journal.
    return [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EdgeJob::$request protected property Request data.
EdgeJob::$response protected property Response data.
EdgeJob::execute public function Executes this job. Overrides Job::execute 1
EdgeJob::executeRequest abstract protected function Executes the request itself. 3
EdgeJob::getConnector protected function Returns the SDK connector instance from the global container.
EdgeJob::renderArray public function Returns this job's visual representation. Overrides Job::renderArray
Job::$exceptions protected property Exception storage.
Job::$id private property Job ID.
Job::$messages protected property Messages storage.
Job::$retry protected property Remaining retries.
Job::$status protected property Job status.
Job::$tag private property The tag of the job.
Job::ALL_STATUSES protected constant Job statuses.
Job::consumeRetry public function Consumes a retry.
Job::FAILED public constant Job is failed, and it won't be retried.
Job::FINISHED public constant Job is finished successfully.
Job::getExceptions public function Gets all stored exception data.
Job::getId public function Gets the job id.
Job::getMessages public function Gets all stored messages.
Job::getStatus public function Gets the status of the job.
Job::getTag public function Gets the job tag.
Job::IDLE public constant Job is waiting to be picked up by a worker.
Job::recordException public function Adds an exception to the exception storage.
Job::recordMessage public function Adds a message to the message storage.
Job::RESCHEDULED public constant Job failed, waiting to be retried.
Job::RUNNING public constant Job is running.
Job::SELECTED public constant Job is claimed by a worker, but not running yet.
Job::setStatus public function Sets the status of the job.
Job::setTag public function Sets the job tag.
Job::shouldRetry public function Whether this job should be retried when an exception is thrown.
Job::__construct public function Job constructor. 3
Job::__toString abstract public function Returns this job's textual representation. 5