You are here

public function MaestroOrchestrator::orchestrate in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Controller/MaestroOrchestrator.php \Drupal\maestro\Controller\MaestroOrchestrator::orchestrate()

Orchestrator method This method is called by the menu router for /orchestrator This runs the Maestro Engine.

1 call to MaestroOrchestrator::orchestrate()
MaestroOrchestrator::startProcess in src/Controller/MaestroOrchestrator.php
Method used to start a process.
1 string reference to 'MaestroOrchestrator::orchestrate'
maestro.routing.yml in ./maestro.routing.yml
maestro.routing.yml

File

src/Controller/MaestroOrchestrator.php, line 21

Class

MaestroOrchestrator
Maestro Orchestrator class.

Namespace

Drupal\maestro\Controller

Code

public function orchestrate($token = '', $skip_response = FALSE) {
  if ($token == '') {

    // bad!  must have a value.
    return new Response('Missing Orchestrator Token', 500);
  }
  $config = $this
    ->config('maestro.settings');
  if ($config
    ->get('maestro_orchestrator_token') != $token) {
    return new Response('Wrong Orchestrator Token', 500);
  }
  $engine = new MaestroEngine();
  $lockDurationTime = $config
    ->get('maestro_orchestrator_lock_execution_time');
  if (intval($lockDurationTime) <= 0) {
    $lockDurationTime = 30;
  }
  $lock = \Drupal::lock();
  if ($lock
    ->acquire('maestro_orchestrator', $lockDurationTime)) {

    // TODO: Handle exceptions being thrown.
    // leaving it like this will simply stall the orchestrator execution for the time being
    // How to gracefully continue?  One process failing will stall the entire engine.
    // Check if dev mode option is enabled.
    if ($config
      ->get('maestro_orchestrator_development_mode') == '1') {

      // Does a cache reset before loading entities during orchestration.
      $engine
        ->enableDevelopmentMode();
    }
    $engine
      ->cleanQueue();
    $lock
      ->release('maestro_orchestrator');
  }
  if ($engine
    ->getDebug()) {
    return [
      '#markup' => 'debug orchestrator done',
    ];
  }
  else {

    // See CronController::run as we do the same thing to return a 204 with no content to satisfy the return response.
    if (!$skip_response) {
      return new Response('', 204);
    }
  }
}