/**
  * @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;
 }
 public function testSetStatus()
 {
     $a = new IndexingTaskStatusQueryResponse();
     $a->setStatus('FAILED');
     $this->assertEquals('FAILED', $a->getStatus());
     $a->setStatus('SUCCESS');
     $this->assertEquals('SUCCESS', $a->getStatus());
 }
 /**
  * Hook function to parse the task status from the response from server.
  *
  * This hook must return the response, whether changed or not, so that the rest of the system can continue with it.
  *
  * @param Response $response
  * @return IndexingTaskStatusQueryResponse|mixed
  * @throws \Exception
  */
 public function handleResponse($response)
 {
     $taskStatus = new IndexingTaskStatusQueryResponse();
     $response = $response->json();
     if (!isset($response['status'])) {
         throw new \Exception("Unexpected response");
         // TODO Replace with subclassed exception
     }
     $responseStatus = $response['status'];
     if (!isset($response['task'])) {
         throw new \Exception("Unexpected response");
         // TODO Replace with subclassed exception
     }
     $taskStatus->setTask($response['task']);
     if (!isset($responseStatus['id'])) {
         throw new \Exception("Unexpected response");
         // TODO Replace with subclassed exception
     }
     $taskStatus->setId($responseStatus['id']);
     if (!isset($responseStatus['status'])) {
         throw new \Exception("Unexpected response");
         // TODO Replace with subclassed exception
     }
     $taskStatus->setStatus($responseStatus['status']);
     if (!isset($responseStatus['duration'])) {
         throw new \Exception("Unexpected response");
         // TODO Replace with subclassed exception
     }
     $taskStatus->setDuration($responseStatus['duration']);
     return $taskStatus;
 }
 public function getGenericQueryResponse()
 {
     $taskStatus = new IndexingTaskStatusQueryResponse();
     $taskStatus->setStatus('RUNNING');
     $taskStatus->setDuration(1);
     $taskStatus->setId('task.id');
     $taskStatus->setTask('task.id');
     return $taskStatus;
 }