You are here

public function TaskRunner::executeTasks in Webform Scheduled Tasks 8.2

Execute all pending tasks.

Parameters

\Drupal\webform_scheduled_tasks\Entity\WebformScheduledTaskInterface[] $tasks: A list of tasks to execute, regardless of their eligibility.

Overrides TaskRunnerInterface::executeTasks

File

src/TaskRunner.php, line 41

Class

TaskRunner
A task runner used for executing scheduled tasks.

Namespace

Drupal\webform_scheduled_tasks

Code

public function executeTasks(array $scheduled_tasks) {
  foreach ($scheduled_tasks as $scheduled_task) {
    $result_set = $scheduled_task
      ->getResultSetPlugin();
    $task = $scheduled_task
      ->getTaskPlugin();
    try {
      $task
        ->executeTask($result_set
        ->getResultSet());
      $scheduled_task
        ->registerSuccessfulTask();
      $scheduled_task
        ->incrementTaskRunDateByInterval();
    } catch (HaltScheduledTaskException $e) {

      // Catch and exception which should halt running the task entirely.
      $scheduled_task
        ->registerFailedTask($e);
      $scheduled_task
        ->halt(sprintf('An error was encountered when running the task: %s', $e
        ->getMessage()));
    } catch (RetryScheduledTaskException $e) {

      // Catch an exception type which has a high chance of success if the
      // task is simply run again.
      $scheduled_task
        ->registerFailedTask($e);
      $scheduled_task
        ->incrementTaskRunDateByInterval();
    } catch (\Exception $e) {

      // By default, unless a retry exception is thrown, halt the task and
      // add an error message.
      $scheduled_task
        ->registerFailedTask($e);
      $scheduled_task
        ->halt(sprintf('An error was encountered when running the task: %s', $e
        ->getMessage()));
    }
  }
}