/**
  * @param IndexingTaskStatusQueryResponse $response
  * @return bool
  * @throws \Exception
  */
 public function handleTaskStatus(IndexingTaskStatusQueryResponse $response)
 {
     $taskStatus = $response->getStatus();
     if ($taskStatus === 'RUNNING') {
         if ($this->watchAttempts < $this->maximumWatchAttempts) {
             $this->onJobPending();
             $jobId = $response->getTask();
             $this->doWait($this->watchAttemptDelay);
             return $this->watchJob($jobId);
         } else {
             $this->stopWatchingJob();
             $this->onJobFailed();
             return false;
         }
     } else {
         if ($taskStatus === 'SUCCESS') {
             $this->stopWatchingJob();
             $this->onJobCompleted();
             return true;
         } else {
             if ($taskStatus === 'FAILED') {
                 $this->stopWatchingJob();
                 $this->onJobFailed();
                 return false;
             } else {
                 throw new \Exception('Unexpected task status encountered: "' . $taskStatus . '"');
             }
         }
     }
     return false;
 }